mirror of https://github.com/dapr/dapr-agents.git
Merge branch 'main' into cyb3rward0g/clean-update-elevenlabs
This commit is contained in:
commit
d2deff4b20
|
|
@ -10,7 +10,7 @@ This quickstart provides a hands-on introduction to Dapr Agents through simple e
|
|||
|
||||
## Environment Setup
|
||||
|
||||
### Option 1: Using pip (Traditional)
|
||||
### Option 1: Using pip (Recommended)
|
||||
|
||||
```bash
|
||||
# Create a virtual environment
|
||||
|
|
@ -23,14 +23,11 @@ python3.10 -m venv .venv
|
|||
source .venv/bin/activate
|
||||
|
||||
# Install dependencies
|
||||
pip-compile pyproject.toml
|
||||
pip install -r requirements.txt
|
||||
|
||||
# For vectorstore functionality (optional)
|
||||
pip install sentence-transformers chromadb 'posthog<6.0.0'
|
||||
```
|
||||
|
||||
### Option 2: Using uv (Recommended)
|
||||
### Option 2: Using uv
|
||||
|
||||
```bash
|
||||
# Create and activate virtual environment
|
||||
|
|
@ -39,20 +36,6 @@ source .venv/bin/activate
|
|||
|
||||
# Install core dependencies
|
||||
uv pip install -r requirements.txt
|
||||
|
||||
# For vectorstore functionality (optional)
|
||||
uv add sentence-transformers chromadb 'posthog<6.0.0'
|
||||
```
|
||||
|
||||
### Option 3: Install with extras (uv only)
|
||||
|
||||
```bash
|
||||
# Create and activate virtual environment
|
||||
uv venv .venv
|
||||
source .venv/bin/activate
|
||||
|
||||
# Install with vectorstore extras
|
||||
uv pip install -e ".[vectorstore]"
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
|
@ -243,6 +226,7 @@ if __name__ == "__main__":
|
|||
load_dotenv()
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
### Interacting with the Agent
|
||||
|
||||
|
|
@ -338,16 +322,16 @@ if __name__ == '__main__':
|
|||
|
||||
**Prerequisites:** This example requires vectorstore dependencies. Install them using one of these methods:
|
||||
|
||||
**Using uv (recommended):**
|
||||
```bash
|
||||
uv add sentence-transformers chromadb 'posthog<6.0.0'
|
||||
```
|
||||
|
||||
**Using pip:**
|
||||
**Using pip (recommended):**
|
||||
```bash
|
||||
pip install sentence-transformers chromadb 'posthog<6.0.0'
|
||||
```
|
||||
|
||||
**Using uv:**
|
||||
```bash
|
||||
uv add sentence-transformers chromadb 'posthog<6.0.0'
|
||||
```
|
||||
|
||||
**Or install with extras (uv only):**
|
||||
```bash
|
||||
uv pip install -e ".[vectorstore]"
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
-e ../../ # Import the local dapr agents package
|
||||
python-dotenv
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
elevenlabs
|
||||
|
|
@ -1 +1 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
tiktoken
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
tiktoken
|
||||
|
|
@ -236,17 +236,14 @@ dapr run --app-id weatheragent --resources-path ./components -- python weather_a
|
|||
|
||||
## Available Agent Types
|
||||
|
||||
Dapr Agents provides several agent implementations, each designed for different use cases:
|
||||
Dapr Agents provides two agent implementations, each designed for different use cases:
|
||||
|
||||
### 1. Standard Agent (ToolCallAgent)
|
||||
### 1. Agent
|
||||
The default agent type, designed for tool execution and straightforward interactions. It receives your input, determines which tools to use, executes them directly, and provides the final answer. The reasoning process is mostly hidden from you, focusing instead on delivering concise responses.
|
||||
|
||||
### 2. ReActAgent
|
||||
Implements the Reasoning-Action framework for more complex problem-solving with explicit thought processes.
|
||||
When you interact with it, you'll see explicit "Thought", "Action", and "Observation" steps as it works through your request, providing transparency into how it reaches conclusions.
|
||||
### 2. DurableAgent
|
||||
The DurableAgent class is a workflow-based agent that extends the standard Agent with Dapr Workflows for long-running, fault-tolerant, and durable execution. It provides persistent state management, automatic retry mechanisms, and deterministic execution across failures. We will see this agent in the next example.
|
||||
|
||||
### 3. OpenAPIReActAgent
|
||||
There is one more agent that we didn't run in this quickstart. OpenAPIReActAgent specialized agent for working with OpenAPI specifications and API integrations. When you ask about working with an API, it will methodically identify relevant endpoints, construct proper requests with parameters, handle authentication, and execute API calls on your behalf.
|
||||
|
||||
```python
|
||||
from dapr_agents import Agent
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
from dapr_agents.workflow import WorkflowApp, workflow, task
|
||||
from dapr.ext.workflow import DaprWorkflowContext
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
|
||||
# Define Workflow logic
|
||||
@workflow(name="task_chain_workflow")
|
||||
def task_chain_workflow(ctx: DaprWorkflowContext):
|
||||
character = yield ctx.call_activity(get_character)
|
||||
print(f"Character: {character}")
|
||||
line = yield ctx.call_activity(get_line, input={"character": character})
|
||||
print(f"Line: {line}")
|
||||
return line
|
||||
|
||||
|
||||
@task(
|
||||
description="""
|
||||
Pick a random character from The Lord of the Rings\n
|
||||
and respond with the character's name only
|
||||
"""
|
||||
)
|
||||
def get_character() -> str:
|
||||
pass
|
||||
|
||||
|
||||
@task(
|
||||
description="What is a famous line by {character}",
|
||||
)
|
||||
def get_line(character: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
wfapp = WorkflowApp()
|
||||
|
||||
results = wfapp.run_and_monitor_workflow_sync(task_chain_workflow)
|
||||
print(f"Results: {results}")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
requests
|
||||
chainlit
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
mcp
|
||||
starlette
|
||||
|
|
|
|||
|
|
@ -19,29 +19,33 @@ async def main():
|
|||
args=["tools.py"], # Run tools.py directly
|
||||
)
|
||||
|
||||
# Get available tools from the MCP instance
|
||||
tools = client.get_all_tools()
|
||||
print("🔧 Available tools:", [t.name for t in tools])
|
||||
try:
|
||||
tools = client.get_all_tools()
|
||||
print("🔧 Available tools:", [t.name for t in tools])
|
||||
|
||||
# Create the Weather Agent using MCP tools
|
||||
weather_agent = Agent(
|
||||
name="Stevie",
|
||||
role="Weather Assistant",
|
||||
goal="Help humans get weather and location info using MCP tools.",
|
||||
instructions=[
|
||||
"Respond clearly and helpfully to weather-related questions.",
|
||||
"Use tools when appropriate to fetch or simulate weather data.",
|
||||
"You may sometimes jump after answering the weather question.",
|
||||
],
|
||||
tools=tools,
|
||||
)
|
||||
# Create the Weather Agent using MCP tools
|
||||
weather_agent = Agent(
|
||||
name="Stevie",
|
||||
role="Weather Assistant",
|
||||
goal="Help humans get weather and location info using MCP tools.",
|
||||
instructions=[
|
||||
"Respond clearly and helpfully to weather-related questions.",
|
||||
"Use tools when appropriate to fetch or simulate weather data.",
|
||||
"You may sometimes jump after answering the weather question.",
|
||||
],
|
||||
tools=tools,
|
||||
)
|
||||
|
||||
# Run a sample query
|
||||
result = await weather_agent.run("What is the weather in New York?")
|
||||
print(result)
|
||||
# Run a sample query
|
||||
result = await weather_agent.run("What is the weather in New York?")
|
||||
print(result)
|
||||
|
||||
# Clean up resources
|
||||
await client.close()
|
||||
finally:
|
||||
try:
|
||||
await client.close()
|
||||
except RuntimeError as e:
|
||||
if "Attempted to exit cancel scope" not in str(e):
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
dapr-agents>=0.5.0
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
mcp
|
||||
|
|
@ -91,13 +91,16 @@ docker run --rm --name sampledb \
|
|||
Install Postgres:
|
||||
|
||||
```bash
|
||||
# Install and start PostgreSQL
|
||||
brew install postgresql
|
||||
brew services start postgresql
|
||||
|
||||
psql postgres
|
||||
> CREATE USER admin WITH PASSWORD 'mypassword';
|
||||
> CREATE DATABASE userdb
|
||||
> GRANT ALL PRIVILEGES ON DATABASE userdb TO admin;
|
||||
# Create user and database (safe to re-run)
|
||||
psql postgres <<EOF
|
||||
CREATE USER admin WITH PASSWORD 'mypassword';
|
||||
CREATE DATABASE userdb OWNER admin;
|
||||
GRANT ALL PRIVILEGES ON DATABASE userdb TO admin;
|
||||
EOF
|
||||
```
|
||||
|
||||
Next, create the users table and seed data:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
dapr-agents>=0.5.1
|
||||
dapr-agents>=0.6.0
|
||||
python-dotenv
|
||||
chainlit
|
||||
psycopg
|
||||
|
|
|
|||
Loading…
Reference in New Issue