### Contributor Setup: Install Dependencies Source: https://github.com/dapr/dapr-agents/blob/main/README.md Installs development and testing dependencies using uv. This command should be run before making code changes. ```bash uv sync --group dev --group test ``` -------------------------------- ### Setup Python Environment and Dependencies Source: https://github.com/dapr/dapr-agents/blob/main/examples/10-agent-executor-echo/README.md Installs project dependencies using uv. Ensure Python 3.11+ and uv are installed. ```bash uv venv source .venv/bin/activate # Windows: .venv\Scripts\activate uv sync --active ``` -------------------------------- ### Setup Bash Commands Source: https://github.com/dapr/dapr-agents/blob/main/examples/11-expert-agent-tavily/README.md Installs dependencies, activates the virtual environment, and initializes Dapr. Ensure you have `uv` and the Dapr CLI installed. ```bash uv venv source .venv/bin/activate # Windows: .venv\Scripts\activate uv sync --active dapr init # only needed once per machine ``` -------------------------------- ### Setup Development Environment Source: https://github.com/dapr/dapr-agents/blob/main/AGENTS.md Commands to initialize the virtual environment and install dependencies. ```bash uv venv && source .venv/bin/activate && uv sync --group test ``` -------------------------------- ### Execute Setup Script Source: https://github.com/dapr/dapr-agents/blob/main/examples/ext-drasi-change-driven-agents-k8s/README.md Run the provided script to initialize the k3d cluster and install required services. ```bash ./demo-setup.sh ``` -------------------------------- ### Setup Virtual Environment and Install Dependencies Source: https://github.com/dapr/dapr-agents/blob/main/examples/04-multi-agent-workflows/README.md Sets up a Python virtual environment using uv and installs project dependencies. Activate the environment before running other commands. ```bash uv venv # Activate the virtual environment # On Windows: .venv\Scripts\activate # On macOS/Linux: source .venv/bin/activate uv sync --active ``` ```bash uv venv # Activate the virtual environment # On Windows: .venv\Scripts\activate # On macOS/Linux: source .venv/bin/activate # Install dependencies pip install -r requirements.txt ``` -------------------------------- ### Setup Python environment and dependencies Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-dapr-workflow/README.md Installs project dependencies using uv. Ensure you have Python 3.11+ and uv installed. ```bash uv venv source .venv/bin/activate # Windows: .venv\Scripts\activate uv sync --active ``` -------------------------------- ### Install and Configure Postgres via Brew Source: https://github.com/dapr/dapr-agents/blob/main/examples/07-data-agent-mcp-chainlit/README.md Installs PostgreSQL using Homebrew, starts the service, creates a user and database, and then applies schema and seed data. ```bash # Install and start PostgreSQL brew install postgresql brew services start postgresql # Create user and database (safe to re-run) psql postgres < str: """Get weather information for a specific location.""" temperature = random.randint(60, 80) return f"{location}: {temperature}F." ``` -------------------------------- ### Pre-populate Initial PostgreSQL Configuration Source: https://github.com/dapr/dapr-agents/blob/main/examples/09-durable-agent-hot-reload/README.md SQL commands to insert initial configuration values into the PostgreSQL 'configuration' table before starting the agent. This ensures the agent loads existing settings on startup. ```sql INSERT INTO configuration (key, value, version) VALUES ('agent_role', 'Data Scientist', '1'), ('agent_goal', 'Analyze complex datasets', '1'), ('agent_instructions', '["Use tables", "Cite sources"]', '1'), ('max_iterations', '15', '1'); ``` -------------------------------- ### Publish to a Topic Source: https://github.com/dapr/dapr-agents/blob/main/examples/04-multi-agent-workflows/README.md Example of publishing a message to a specific topic using a Python client. Ensure the topic name matches the agent's subscription. ```python pubsub_client.py --topic fellowship.broadcast --task "Emergency: Nazgûl approaching!" ``` -------------------------------- ### Manually Run All Pre-push Hooks Source: https://github.com/dapr/dapr-agents/blob/main/docs/development/README.md Manually execute all configured pre-push hooks on all files in the repository. This is useful for verifying the setup or running checks outside of a git push. ```bash pre-commit run --all-files --hook-stage pre-push ``` -------------------------------- ### Start multiple MCP servers Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-dapr-workflow/README.md Launches two MCP servers on different ports. The first server (weather) handles weather and forecast, while the second server (weather2) handles humidity and wind. ```bash python weather_mcp_server.py --port 8081 # MCPServer "weather": get_weather, get_forecast python weather_mcp_server_2.py --port 8082 # MCPServer "weather2": get_humidity, get_wind ``` -------------------------------- ### Dapr Run with Environment Variables Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-client-streamablehttp/README.md Renders component templates and starts the Dapr application using environment variables for configuration. Ensure the .env file is set up correctly. ```bash export $(grep -v '^#' ../../.env | xargs) temp_resources_folder=$(../resolve_env_templates.py ./components) dapr run \ --app-id weatherappmcp-http \ --app-port 8001 \ --resources-path "$temp_resources_folder" \ -- python app.py rm -rf "$temp_resources_folder" ``` -------------------------------- ### Define Agents with Shared Registry Source: https://github.com/dapr/dapr-agents/blob/main/examples/08-agents-as-tools/README.md Illustrates configuring agents to use a shared registry for auto-discovery. When agents join the registry, they become discoverable by other agents at the start of their workflow runs, simplifying inter-agent communication setup. ```python # OR: shared registry — all peers auto-discovered at workflow start sam = DurableAgent(name="sam", registry=registry, ...) frodo = DurableAgent(name="frodo", registry=registry, ...) ``` -------------------------------- ### Create and Activate Virtual Environment with uv Source: https://github.com/dapr/dapr-agents/blob/main/docs/development/README.md Use `uv` to create a virtual environment and activate it. Then, sync dependencies to ensure the environment is set up correctly. ```bash uv venv source .venv/bin/activate uv sync --active ``` -------------------------------- ### Apply and Wait for Drasi Sources Source: https://github.com/dapr/dapr-agents/blob/main/examples/ext-drasi-change-driven-agents-k8s/README.md Deploy and verify the readiness of Drasi product sources. ```bash drasi apply -f ./drasi/sources/products.yaml drasi wait -f ./drasi/sources/products.yaml -t 120 ``` -------------------------------- ### Install Local Python Dapr Package Changes Source: https://github.com/dapr/dapr-agents/blob/main/docs/development/README.md Install local versions of Dapr Python packages, such as from `python-sdk` or `durabletask-python`, using `uv pip install -e`. Adjust paths as necessary. ```bash uv pip install -e ../durabletask-python \ -e ../python-sdk \ -e ../python-sdk/ext/dapr-ext-fastapi \ -e ../python-sdk/ext/dapr-ext-workflow ``` -------------------------------- ### Basic Text Completion with HFHubChatClient Source: https://github.com/dapr/dapr-agents/blob/main/examples/01-llm-call-hugging-face/README.md Demonstrates basic usage of HFHubChatClient for text generation, including using a prompty file and user input. Ensure environment variables are loaded. ```python from dotenv import load_dotenv from dapr_agents.llm import HFHubChatClient from dapr_agents.types import LLMChatResponse, UserMessage load_dotenv() # Basic chat completion llm = HFHubChatClient(model="HuggingFaceTB/SmolLM3-3B") response: LLMChatResponse = llm.generate("Name a famous dog!") if response.get_message() is not None: print("Response: ", response.get_message().content) # Chat completion using a prompty file for context llm = HFHubChatClient.from_prompty("basic.prompty") response: LLMChatResponse = llm.generate(input_data={"question": "What is your name?"}) if response.get_message() is not None: print("Response with prompty: ", response.get_message().content) # Chat completion with user input llm = HFHubChatClient(model="HuggingFaceTB/SmolLM3-3B") response: LLMChatResponse = llm.generate(messages=[UserMessage("hello")]) if response.get_message() is not None and "hello" in response.get_message().content.lower(): print("Response with user input: ", response.get_message().content) ``` -------------------------------- ### Start Dapr Agent with Component Rendering Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-client-streamablehttp/README.md Renders Dapr component templates and starts the agent application. This command should be run in a separate terminal from the MCP server. ```bash temp_resources_folder=$(../resolve_env_templates.py ./components) dapr run \ --app-id weatherappmcp-http \ --app-port 8001 \ --resources-path "$temp_resources_folder" \ -- python app.py rm -rf "$temp_resources_folder" ``` -------------------------------- ### Configure OpenAI API Key using Environment Variables Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-client-sse/README.md Sets up the OpenAI API key by creating a .env file and exporting it. This method is recommended for managing secrets. ```bash # Get the environment variables from the .env file: export $(grep -v '^#' ../../.env | xargs) # Create a temporary resources folder with resolved environment variables temp_resources_folder=$(../resolve_env_templates.py ./components) # Run your dapr command with the temporary resources uv run dapr run --app-id weatherappmcp --dapr-http-port 3500 --resources-path $temp_resources_folder -- python app.py # Clean up when done rm -rf $temp_resources_folder ``` -------------------------------- ### Start Message Workflow App Source: https://github.com/dapr/dapr-agents/blob/main/examples/03-message-router-workflow/README.md Use this command to start the Dapr application that handles message routing and workflow execution. Ensure the app.py script is in the current directory. ```bash dapr run \ --app-id message-workflow \ --resources-path $temp_resources_folder \ -- python app.py rm -rf $temp_resources_folder ``` -------------------------------- ### Start a New Workflow via REST API Source: https://github.com/dapr/dapr-agents/blob/main/examples/02-durable-agent-tool-call/README.md Uses cURL to send a POST request to the agent's REST API to start a new workflow. The request body contains the task details. ```bash curl -i -X POST http://localhost:8001/agent/run \ -H "Content-Type: application/json" \ -d '{"task": "What's the weather in New York?"}' ``` -------------------------------- ### Configure Elevenlabs API Key Source: https://github.com/dapr/dapr-agents/blob/main/examples/01-llm-call-elevenlabs/README.md Create a .env file in the project root to store your Elevenlabs API key. Replace the placeholder with your actual key. ```env ELEVENLABS_API_KEY=your_api_key_here ``` -------------------------------- ### Loading Prompty Configuration Source: https://github.com/dapr/dapr-agents/blob/main/examples/01-llm-call-anthropic/README.md Loads LLM configuration, including model, parameters, and prompt template, from a Prompty file. Per-call generate(**kwargs) overrides default parameters. ```python from dapr_agents.llm.anthropic.chat import AnthropicChatClient client = AnthropicChatClient.from_prompty("basic.prompty") response = client.generate(input_data={"question": "What is your name?"}) ``` -------------------------------- ### Pull Ollama Model Source: https://github.com/dapr/dapr-agents/blob/main/quickstarts/README.md Pulls a model with tool-calling support from Ollama. Ensure Ollama is installed and running. ```bash ollama serve # Start the server (skip if already running) ollama pull qwen3:0.6b ``` -------------------------------- ### Apply and Wait for Drasi Queries Source: https://github.com/dapr/dapr-agents/blob/main/examples/ext-drasi-change-driven-agents-k8s/README.md Deploy and verify the readiness of stock event queries. ```bash drasi apply -f ./drasi/queries/critical-stock-event.yaml drasi wait -f ./drasi/queries/critical-stock-event.yaml -t 120 drasi apply -f ./drasi/queries/low-stock-event.yaml drasi wait -f ./drasi/queries/low-stock-event.yaml -t 120 ``` -------------------------------- ### Register Drasi Query Subscription Source: https://github.com/dapr/dapr-agents/blob/main/ext/dapr-agents-ext-drasi/README.md Register a Drasi query subscription on an agent before starting the agent runner. ```python agent = DurableAgent(...) drasi_trigger( agent, query_id="", task_mapper=lambda event, ctx: TriggerAction(task="") ) runner = AgentRunner() try: runner.subscribe(agent) await wait_for_shutdown() finally: runner.shutdown(agent) ``` -------------------------------- ### Discover Team Members Source: https://github.com/dapr/dapr-agents/blob/main/examples/04-multi-agent-workflows/README.md Example of an orchestrator querying the agent registry to find all available members of a specific team. ```python # Orchestrator can find all fellowship members available_agents = registry.get_team_members("fellowship") # Returns: [frodo, sam, gandalf, legolas] ``` -------------------------------- ### Run the Durable Agent Source: https://github.com/dapr/dapr-agents/blob/main/quickstarts/README.md Starts the Dapr application for the durable agent. Ensure the Python script is in the correct path. ```bash uv run dapr run --app-id durable-agent --resources-path resources -- python 03_durable_agent_http.py ``` -------------------------------- ### Create .env file for Database Configuration Source: https://github.com/dapr/dapr-agents/blob/main/examples/07-data-agent-mcp-chainlit/README.md Creates a .env file in the root directory with database connection details. This file is used by the application to connect to the Postgres database. ```bash DB_HOST=localhost DB_PORT=5432 DB_NAME=userdb DB_USER=admin DB_PASSWORD=mypassword ``` -------------------------------- ### Build Drasi TypeSpec contract Source: https://github.com/dapr/dapr-agents/blob/main/ext/dapr-agents-ext-drasi/PROVENANCE.md Commands to install dependencies and build the TypeSpec contract from the upstream Drasi platform repository. ```bash cd drasi-platform/typespec npm install npm run build ./output-unpacked ``` -------------------------------- ### Run Postgres MCP Server Source: https://github.com/dapr/dapr-agents/blob/main/examples/07-data-agent-mcp-chainlit/README.md Launches the Postgres MCP server using Docker. Ensure your DATABASE_URI is correctly set in the environment. ```bash docker run --rm -ti -p 8000:8000 \ -e DATABASE_URI=postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME \ crystaldba/postgres-mcp --access-mode=unrestricted --transport=sse ``` -------------------------------- ### Export Environment Variables on macOS/Linux Source: https://github.com/dapr/dapr-agents/blob/main/examples/07-data-agent-mcp-chainlit/README.md Exports environment variables from a .env file. Ensure this is run before starting any Dapr services. ```bash export $(grep -v '^#' .env | xargs) ``` -------------------------------- ### Basic Streaming Response with HFHubChatClient Source: https://github.com/dapr/dapr-agents/blob/main/examples/01-llm-call-hugging-face/README.md Demonstrates how to receive and process streaming LLM responses token-by-token using HFHubChatClient. Useful for real-time output. ```python from dotenv import load_dotenv from dapr_agents import HFHubChatClient from dapr_agents.types.message import LLMChatResponseChunk from typing import Iterator import logging logging.basicConfig(level=logging.INFO) load_dotenv() llm = HFHubChatClient(model="HuggingFaceTB/SmolLM3-3B") response: Iterator[LLMChatResponseChunk] = llm.generate("Name a famous dog!", stream=True) for chunk in response: if chunk.result.content: print(chunk.result.content, end="", flush=True) ``` -------------------------------- ### Apply and Wait for Drasi Reactions Source: https://github.com/dapr/dapr-agents/blob/main/examples/ext-drasi-change-driven-agents-k8s/README.md Deploy and verify the readiness of the inventory events publisher reaction. ```bash drasi apply -f ./drasi/reactions/inventory-events-publisher.yaml drasi wait -f ./drasi/reactions/inventory-events-publisher.yaml -t 120 ``` -------------------------------- ### Run Dapr Application Source: https://github.com/dapr/dapr-agents/blob/main/examples/10-agent-executor-echo/README.md Starts the Dapr application with the echo executor. This command requires Dapr CLI and a running Dapr runtime. ```bash dapr run \ --app-id echo-executor-app \ --resources-path ./resources \ -- \ python app.py ``` -------------------------------- ### Run Cross-App Scenario Source: https://github.com/dapr/dapr-agents/blob/main/examples/08-agents-as-tools/README.md Starts the cross-app scenario where each agent has its own Dapr sidecar. This is suitable for distributed systems where agents run in separate applications. ```bash cd examples/09-agents-as-tools dapr run -f dapr-cross-app.yaml ``` -------------------------------- ### Publish Test Message Source: https://github.com/dapr/dapr-agents/blob/main/examples/03-message-router-workflow/README.md Execute this command to start the Dapr client application for publishing test messages to the workflow. This requires the message_client.py script. ```bash dapr run \ --app-id message-workflow-client \ --resources-path $temp_resources_folder \ -- python message_client.py rm -rf $temp_resources_folder ``` -------------------------------- ### Configure OpenAI API Key Source: https://github.com/dapr/dapr-agents/blob/main/examples/01-llm-call-open-ai/README.md Create a .env file in the project root to store your OpenAI API key. Replace 'your_api_key_here' with your actual key. ```env OPENAI_API_KEY=your_api_key_here ``` -------------------------------- ### Run Makefile Shortcuts for Dapr Agents Source: https://github.com/dapr/dapr-agents/blob/main/docs/development/README.md Use Makefile shortcuts to run pre-commit hooks and integration tests. `hooks-run` executes all hooks, while `hooks-run-all` includes integration tests for a comprehensive check. ```bash make hooks-run ``` ```bash make hooks-run-all ``` -------------------------------- ### Launch the Agent with Dapr Source: https://github.com/dapr/dapr-agents/blob/main/examples/10-mcpserver/README.md Starts the Dapr agent, connecting it to the weather MCP server. This command loads the MCPServer resource and registers necessary workflows. ```bash cd examples/10-mcpserver dapr run \ --app-id mcp-agent \ --resources-path ./resources \ -- python agent.py ``` -------------------------------- ### Run Parallel LLM Task Workflow (Fan-out/Fan-in) Source: https://github.com/dapr/dapr-agents/blob/main/examples/03-llm-based-workflows/README.md Launch a workflow that implements the fan-out/fan-in pattern for research. It generates questions, gathers answers in parallel, and then synthesizes a final report. This demonstrates concurrent execution of multiple activities. ```bash uv run dapr run --app-id dapr-agent-research --resources-path $temp_resources_folder -- python 04_parallel_workflow.py ``` -------------------------------- ### Manually connect and retrieve tools using DaprMCPClient Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-dapr-workflow/README.md Demonstrates how to bypass auto-discovery by manually connecting to an MCP server and retrieving its tools using DaprMCPClient. This is useful for custom tool integration. ```python from dapr.ext.workflow import DaprMCPClient from dapr_agents.tool.mcp import mcp_tool_def_to_workflow_tool client = DaprMCPClient(timeout_in_seconds=30) client.connect("weather") tools = [mcp_tool_def_to_workflow_tool(t) for t in client.get_all_tools()] agent = DurableAgent(name="WeatherAgent", tools=tools, ...) ``` -------------------------------- ### Run Dapr agent with single MCP server Source: https://github.com/dapr/dapr-agents/blob/main/examples/06-agent-mcp-dapr-workflow/README.md Starts the Dapr agent, automatically discovering the 'weather' MCP server resource defined in resources/weather-mcp.yaml. ```bash dapr run --app-id mcp-agent --resources-path ./resources -- python mcp_dapr_workflow.py ``` -------------------------------- ### List Drasi Resources Source: https://github.com/dapr/dapr-agents/blob/main/examples/ext-drasi-change-driven-agents-k8s/README.md Verify the status of deployed Drasi sources, queries, and reactions. ```bash drasi list source drasi list query drasi list reaction ``` -------------------------------- ### Deploy Agent Manifests Source: https://github.com/dapr/dapr-agents/blob/main/examples/04-multi-agent-workflow-k8s/README.md Apply the Kubernetes manifests to deploy the agents. This command assumes the manifests are located in the 'manifests/' directory. ```bash kubectl apply -f manifests/ ```