### Run ADK Web UI for Example Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/4-structured-outputs/README.md Navigates to the example directory and starts the ADK web user interface, allowing interaction with the defined agents, including the email generator. ```bash cd 4-structured-outputs adk web ``` -------------------------------- ### Run ADK Interactive Web UI Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/3-litellm-agent/README.md Command to start the ADK interactive web user interface, which allows interacting with the deployed agent. ```bash adk web ``` -------------------------------- ### Start ADK API Server Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Command to launch a FastAPI server for the ADK agent, enabling testing via API requests. ```Bash adk api_server ``` -------------------------------- ### Launch ADK Web UI Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Command to start the interactive web user interface provided by the ADK CLI for testing and interacting with your agent. ```Bash adk web ``` -------------------------------- ### Running the ADK Persistent Storage Example in Python Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Command to execute the main Python script for the persistent storage example, which initializes the database session service and starts the agent interaction. ```bash python main.py ``` -------------------------------- ### Run ADK Web UI Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/11-parallel-agent/README.md Changes the directory to the example folder and starts the ADK web user interface to interact with the agent. ```bash cd 10-parallel-agent adk web ``` -------------------------------- ### Example .env File Content (Configuration) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Example content for a `.env` file, showing how to set the `GOOGLE_API_KEY` environment variable. This key is required for certain ADK functionalities, and the file should be created in each agent directory. ```bash GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Launching ADK Web UI - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/1-basic-agent/README.md Command to start the interactive web user interface provided by the ADK CLI tool. This allows testing and interacting with the agent via a chat interface, typically accessible at http://localhost:8000. ```bash adk web ``` -------------------------------- ### Running the Stateful Multi-Agent Example - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Execute the main Python script to start the stateful multi-agent application. This initializes a new session, begins an interactive conversation, and tracks interactions in the session state. ```bash python main.py ``` -------------------------------- ### Activate Python Virtual Environment Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/3-litellm-agent/README.md Commands to activate the Python virtual environment created in the root directory, necessary for running the ADK example. ```bash # macOS/Linux: source ../.venv/bin/activate ``` ```bash # Windows CMD: ..\.venv\Scripts\activate.bat ``` ```bash # Windows PowerShell: ..\.venv\Scripts\Activate.ps1 ``` -------------------------------- ### Activating Virtual Environment (Bash/CMD/PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Commands to activate the Python virtual environment created during the setup process, providing the necessary environment for running the example script. ```bash source ../.venv/bin/activate ``` ```cmd ..\.\venv\Scripts\activate.bat ``` ```powershell ..\.\venv\Scripts\Activate.ps1 ``` -------------------------------- ### Starting ADK Interactive Web UI (Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md This command starts the interactive web user interface for the Agent Development Kit from the current directory, allowing users to interact with the defined agents via a web browser. ```bash adk web ``` -------------------------------- ### Configure LiteLLM Model (GPT-4o via OpenRouter) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/3-litellm-agent/README.md Example Python code snippet showing how to configure the LiteLlm model adapter to use OpenAI's GPT-4o model accessed through OpenRouter. ```python # To use GPT-4o from OpenAI through OpenRouter model = LiteLlm( model="openrouter/openai/gpt-4o", api_key=os.getenv("OPENROUTER_API_KEY"), ) ``` -------------------------------- ### Configure LiteLLM Model (Llama 3 70B via OpenRouter) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/3-litellm-agent/README.md Example Python code snippet showing how to configure the LiteLlm model adapter to use Meta's Llama 3 70B Instruct model accessed through OpenRouter. ```python # To use Llama 3 70B from Meta through OpenRouter model = LiteLlm( model="openrouter/meta-llama/meta-llama-3-70b-instruct", api_key=os.getenv("OPENROUTER_API_KEY"), ) ``` -------------------------------- ### Running the Stateful Session Example (Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Command to execute the main Python script that demonstrates the creation and usage of a stateful session with the question-answering agent. ```bash python basic_stateful_session.py ``` -------------------------------- ### Running the LinkedIn Post Generator ADK Example Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/12-loop-agent/README.md Provides the necessary shell commands to change into the example directory and launch the ADK web interface, allowing the user to interact with the LinkedIn Post Generator agent. ```bash cd 11-loop-agent adk web ``` -------------------------------- ### Implementing ADK Agent Callbacks (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Demonstrates how to use `before_agent_callback` to log the start time and increment a request counter in session state, and `after_agent_callback` to calculate and log the request duration. Requires access to `CallbackContext` and session state. ```Python def before_agent_callback(callback_context: CallbackContext) -> Optional[types.Content]: # Get the session state state = callback_context.state # Initialize request counter if "request_counter" not in state: state["request_counter"] = 1 else: state["request_counter"] += 1 # Store start time for duration calculation state["request_start_time"] = datetime.now() # Log the request logger.info("=== AGENT EXECUTION STARTED ===") return None # Continue with normal agent processing def after_agent_callback(callback_context: CallbackContext) -> Optional[types.Content]: # Get the session state state = callback_context.state # Calculate request duration duration = None if "request_start_time" in state: duration = (datetime.now() - state["request_start_time"]).total_seconds() # Log the completion logger.info("=== AGENT EXECUTION COMPLETED ===") return None # Continue with normal agent processing ``` -------------------------------- ### Unsupported: Mixing Built-in Tools in ADK Python Agent Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Demonstrates an unsupported configuration where a single ADK agent is initialized with multiple built-in tools (Code Execution and Google Search). This setup is currently not allowed. ```Python root_agent = Agent( name="RootAgent", model="gemini-2.0-flash", description="Root Agent", tools=[built_in_code_execution, google_search], # NOT SUPPORTED ) ``` -------------------------------- ### Configure LiteLLM Model (Mistral Large via OpenRouter) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/3-litellm-agent/README.md Example Python code snippet showing how to configure the LiteLlm model adapter to use Mistral AI's Mistral Large model accessed through OpenRouter. ```python # To use Mistral Large through OpenRouter model = LiteLlm( model="openrouter/mistral/mistral-large-latest", api_key=os.getenv("OPENROUTER_API_KEY"), ) ``` -------------------------------- ### Activating Virtual Environment (Windows CMD) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Command to activate a Python virtual environment located in the parent directory's `.venv` folder on Windows systems using the Command Prompt. This prepares the environment for running ADK examples. ```bash ...venv\Scripts\activate.bat ``` -------------------------------- ### Configure LiteLLM Model (Claude 3.5 Sonnet via OpenRouter) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/3-litellm-agent/README.md Example Python code snippet showing how to configure the LiteLlm model adapter to use Anthropic's Claude 3.5 Sonnet model accessed through OpenRouter. ```python # To use Claude 3.5 Sonnet from Anthropic through OpenRouter model = LiteLlm( model="openrouter/anthropic/claude-3-5-sonnet", api_key=os.getenv("OPENROUTER_API_KEY"), ) ``` -------------------------------- ### Running ADK Web UI (Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Commands to change the current directory to `8-callbacks` and then run the ADK web user interface using the `adk web` command. This launches the local server to interact with the configured agents. ```bash cd 8-callbacks adk web ``` -------------------------------- ### Configuring Google API Key (.env) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Example content for the .env file, showing how to set the GOOGLE_API_KEY environment variable required for the agent to function. ```plaintext GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Activating Virtual Environment (Windows PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Command to activate a Python virtual environment located in the parent directory's `.venv` folder on Windows systems using PowerShell. This prepares the environment for running ADK examples. ```powershell ...venv\Scripts\Activate.ps1 ``` -------------------------------- ### Setting Up Python Virtual Environment and Dependencies (Bash/Shell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/README.md Provides commands to create a Python virtual environment, activate it for different operating systems (macOS/Linux, Windows CMD, Windows PowerShell), and install project dependencies from a requirements.txt file using pip. ```bash # Create virtual environment in the root directory python -m venv .venv # Activate (each new terminal) # macOS/Linux: source .venv/bin/activate # Windows CMD: .venv\Scripts\activate.bat # Windows PowerShell: .venv\Scripts\Activate.ps1 # Install dependencies pip install -r requirements.txt ``` -------------------------------- ### Activating Virtual Environment (macOS/Linux Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Command to activate a Python virtual environment located in the parent directory's `.venv` folder on macOS or Linux systems using the Bash shell. This prepares the environment for running ADK examples. ```bash source ../.venv/bin/activate ``` -------------------------------- ### Run ADK Web UI - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/10-sequential-agent/README.md Command to start the ADK web user interface, which allows interacting with the agents defined in the current project directory. This launches the local server for testing the agents. ```Bash adk web ``` -------------------------------- ### Activating Virtual Environment (macOS/Linux) - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/1-basic-agent/README.md Command to activate the Python virtual environment created in the root directory on macOS and Linux systems. This is required before running ADK commands. ```bash source ../.venv/bin/activate ``` -------------------------------- ### Activate ADK Virtual Environment (Windows CMD) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Command to activate the Python virtual environment created in the root directory on Windows using the Command Prompt. ```Bash ..\.venv\Scripts\activate.bat ``` -------------------------------- ### Activate ADK Virtual Environment (Windows PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Command to activate the Python virtual environment created in the root directory on Windows using PowerShell. ```Bash ..\.venv\Scripts\Activate.ps1 ``` -------------------------------- ### Activate ADK Virtual Environment (macOS/Linux Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Command to activate the Python virtual environment created in the root directory on macOS or Linux systems using Bash. ```Bash source ../.venv/bin/activate ``` -------------------------------- ### Initializing InMemorySessionService (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Code snippet demonstrating the initialization of the InMemorySessionService, which is used in this example to store and manage sessions directly in memory. ```python session_service = InMemorySessionService() ``` -------------------------------- ### Activating Virtual Environment (Windows CMD) - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/1-basic-agent/README.md Command to activate the Python virtual environment created in the root directory using the Windows Command Prompt. This is required before running ADK commands. ```bash .. .venv\Scripts\activate.bat ``` -------------------------------- ### Activate Python Virtual Environment Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/4-structured-outputs/README.md Commands to activate the Python virtual environment created in the project's root directory, preparing the environment to run the ADK example. ```bash # macOS/Linux: source ../.venv/bin/activate ``` ```bash # Windows CMD: ..\.\venv\Scripts\activate.bat ``` ```bash # Windows PowerShell: ..\.\venv\Scripts\Activate.ps1 ``` -------------------------------- ### Activating Virtual Environment (Windows PowerShell) - PowerShell Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/1-basic-agent/README.md Command to activate the Python virtual environment created in the root directory using Windows PowerShell. This is required before running ADK commands. ```powershell .. .venv\Scripts\Activate.ps1 ``` -------------------------------- ### Setting Google API Key in .env File Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Example content for the .env file, showing how to configure the Google API key required for the ADK agent to interact with Gemini models. ```text GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Activating Python Virtual Environment (Windows CMD) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Command to activate the Python virtual environment on Windows using the Command Prompt, preparing the environment to run the ADK example. ```bash ..\.venv\Scripts\activate.bat ``` -------------------------------- ### Activating Python Virtual Environment (Windows PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Command to activate the Python virtual environment on Windows using PowerShell, preparing the environment to run the ADK example. ```bash ..\.venv\Scripts\Activate.ps1 ``` -------------------------------- ### Run ADK Agent in Terminal Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Command to execute the specified ADK agent directly within the terminal, allowing for command-line interaction. ```Bash adk run tool_agent ``` -------------------------------- ### Add Google API Key to .env - Configuration Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/10-sequential-agent/README.md Example configuration line to add to the `.env` file, setting the `GOOGLE_API_KEY` environment variable required by the ADK agents. Replace `your_api_key_here` with your actual API key. ```Configuration GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Change Directory to Project - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/10-sequential-agent/README.md Command to change the current directory to the specific project folder containing the Sequential Agent example. This is a necessary step before running ADK commands specific to this project. ```Bash cd 9-sequential-agent ``` -------------------------------- ### Activating Python Virtual Environment (macOS/Linux) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md This command activates the Python virtual environment located in the parent directory's `.venv` folder on macOS or Linux systems, preparing the environment to run the ADK example. ```bash source ../.venv/bin/activate ``` -------------------------------- ### Activating Python Virtual Environment (macOS/Linux Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Command to activate the Python virtual environment on macOS or Linux using a Bash-like shell, preparing the environment to run the ADK example. ```bash source ../.venv/bin/activate ``` -------------------------------- ### Activating Python Virtual Environment (Windows CMD) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md This command activates the Python virtual environment located in the parent directory's `.venv` folder using the Windows Command Prompt, preparing the environment to run the ADK example. ```batch ..\.venv\Scripts\activate.bat ``` -------------------------------- ### Recording Tool Usage in ADK Tool Callback State (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Illustrates how to use the ToolContext object within a tool callback function. It shows how to access and modify the session state (tool_context.state) to track which tools have been used during the agent's execution, demonstrating state persistence across tool calls. ```python def before_tool_callback(tool: BaseTool, args: Dict[str, Any], tool_context: ToolContext): # Record tool usage in state tools_used = tool_context.state.get("tools_used", []) tools_used.append(tool.name) tool_context.state["tools_used"] = tools_used ``` -------------------------------- ### Activating Python Virtual Environment (Windows PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md This command activates the Python virtual environment located in the parent directory's `.venv` folder using Windows PowerShell, preparing the environment to run the ADK example. ```powershell ..\.venv\Scripts\Activate.ps1 ``` -------------------------------- ### Implementing ADK Tool Callbacks (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Demonstrates how to implement `before_tool_callback` to modify tool arguments or block requests and `after_tool_callback` to modify tool responses. These functions are executed before and after a tool call, respectively, allowing for custom logic based on tool inputs and outputs. ```python def before_tool_callback( tool: BaseTool, args: Dict[str, Any], tool_context: ToolContext ) -> Optional[Dict]: # Modify arguments (e.g., convert "USA" to "United States") if args.get("country", "").lower() == "merica": args["country"] = "United States" return None # Skip the call completely for restricted countries if args.get("country", "").lower() == "restricted": return {"result": "Access to this information has been restricted."} return None # Proceed with normal tool call def after_tool_callback( tool: BaseTool, args: Dict[str, Any], tool_context: ToolContext, tool_response: Dict ) -> Optional[Dict]: # Add a note for any USA capital responses if "washington" in tool_response.get("result", "").lower(): modified_response = copy.deepcopy(tool_response) modified_response["result"] = f"{tool_response['result']} (Note: This is the capital of the USA. 🇺🇸)" return modified_response return None # Use original response ``` -------------------------------- ### Unsupported: Mixing Built-in and Custom Tools in ADK Python Agent Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/2-tool-agent/README.md Illustrates an unsupported configuration where an ADK agent attempts to combine a built-in tool (Google Search) with a custom function tool (`get_current_time`). This combination is not currently supported in a single agent. ```Python def get_current_time() -> dict: """Get the current time in the format YYYY-MM-DD HH:MM:SS""" return { "current_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), } root_agent = Agent( name="RootAgent", model="gemini-2.0-flash", description="Root Agent", tools=[google_search, get_current_time], # NOT SUPPORTED ) ``` -------------------------------- ### Implementing ADK Model Callbacks (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Shows how `before_model_callback` can filter content by checking the user message and returning a response to bypass the model call, and how `after_model_callback` can modify the model's response through simple word replacements. Requires `CallbackContext`, `LlmRequest`, and `LlmResponse`. ```Python def before_model_callback( callback_context: CallbackContext, llm_request: LlmRequest ) -> Optional[LlmResponse]: # Check for inappropriate content if last_user_message and "sucks" in last_user_message.lower(): # Return a response to skip the model call return LlmResponse( content=types.Content( role="model", parts=[ types.Part( text="I cannot respond to messages containing inappropriate language..." ) ], ) ) # Return None to proceed with normal model request return None def after_model_callback( callback_context: CallbackContext, llm_response: LlmResponse ) -> Optional[LlmResponse]: # Simple word replacements replacements = { "problem": "challenge", "difficult": "complex", } # Perform replacements and return modified response ``` -------------------------------- ### Accessing State and Context in ADK Callback (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Demonstrates how to access the CallbackContext object within an ADK callback function. It shows how to retrieve data from the session state using callback_context.state and how to access agent and invocation details like agent_name and invocation_id for logging or monitoring purposes. ```python def my_callback(callback_context: CallbackContext, ...): # Access the state to store or retrieve data user_name = callback_context.state.get("user_name", "Unknown") # Log the current agent and invocation print(f"Agent {callback_context.agent_name} executing (ID: {callback_context.invocation_id})") ``` -------------------------------- ### Modifying LLM Response in ADK Model Callback (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Demonstrates how to use the LlmResponse object in an after_model_callback to inspect and modify the response received from the LLM. It shows how to access the model's text output (llm_response.content.parts[0].text) and alter it before it is returned to the user or passed to the next step in the agent workflow. ```python def after_model_callback(callback_context: CallbackContext, llm_response: LlmResponse): # Access the model's text response if llm_response.content and llm_response.content.parts: response_text = llm_response.content.parts[0].text # Modify the response modified_text = transform_text(response_text) llm_response.content.parts[0].text = modified_text return llm_response ``` -------------------------------- ### Intercepting LLM Request in ADK Model Callback (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/9-callbacks/README.md Shows how to use the LlmRequest object in a before_model_callback to inspect the incoming request before it reaches the LLM. It demonstrates accessing conversation history (llm_request.contents) to find the last user message and potentially bypass the model call by returning an LlmResponse early based on custom logic (e.g., content filtering). ```python def before_model_callback(callback_context: CallbackContext, llm_request: LlmRequest): # Get the last user message for analysis last_message = None for content in reversed(llm_request.contents): if content.role == "user" and content.parts: last_message = content.parts[0].text break # Analyze the user's message if last_message and contains_sensitive_info(last_message): # Return a response that bypasses the model call return LlmResponse(...) ``` -------------------------------- ### Configuring Google API Key in .env File (Env) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/README.md Shows the required format for setting the Google API key in a .env file. Users need to replace the placeholder with their actual API key obtained from Google AI Studio. ```env GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Initializing Runner with Session Service (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Shows how to initialize the ADK Runner, passing the agent and the configured session service to enable stateful interactions and session management during agent execution. ```python runner = Runner( agent=question_answering_agent, app_name=APP_NAME, session_service=session_service, ) ``` -------------------------------- ### Initializing ADK Session State (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Demonstrates how to use ADK's InMemorySessionService to create and initialize a user session with default state, including user information, purchased courses, and an empty interaction history. ```python session_service = InMemorySessionService() def initialize_state(): """Initialize the session state with default values.""" return { "user_name": "Brandon Hancock", "purchased_courses": [""], "interaction_history": [], } # Create a new session with initial state session_service.create_session( app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID, state=initialize_state(), ) ``` -------------------------------- ### Creating a New Session (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Code snippet showing how to use the session service to create a new session instance, associating it with application, user, and session IDs, and providing the initial state. ```python stateful_session = session_service.create_session( app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID, state=initial_state, ) ``` -------------------------------- ### Set Google API Key in .env Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/4-structured-outputs/README.md Instructions and code snippet for creating a `.env` file and adding the Google API key required for the ADK agent to function. ```bash GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Defining Initial Session State (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Python dictionary defining the initial state for a session, containing user-specific information and preferences that the agent can access. ```python initial_state = { "user_name": "Brandon Hancock", "user_preferences": """ I like to play Pickleball, Disc Golf, and Tennis. My favorite food is Mexican. My favorite TV show is Game of Thrones. Loves it when people like and subscribe to his YouTube channel. """, } ``` -------------------------------- ### Initializing Database Session Service in ADK Python Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Demonstrates how to create an instance of the DatabaseSessionService, specifying the database URL. This service handles the connection and schema management for persistent storage. ```python from google.adk.sessions import DatabaseSessionService db_url = "sqlite:///./my_agent_data.db" session_service = DatabaseSessionService(db_url=db_url) ``` -------------------------------- ### Activate Virtual Environment (Windows CMD) - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/10-sequential-agent/README.md Command to activate the Python virtual environment on Windows using Command Prompt, executed from the project root directory. This prepares the environment for running ADK commands. ```Bash ..\.venv\Scripts\activate.bat ``` -------------------------------- ### Defining Root Agent with Sub-Agent Delegation (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Shows the definition of the main customer service agent using the ADK Agent class. It includes setting the model, description, instructions, and crucially, listing the specialized sub-agents it can delegate tasks to, along with any tools it uses. ```python customer_service_agent = Agent( name="customer_service", model="gemini-2.0-flash", description="Customer service agent for AI Developer Accelerator community", instruction=""" You are the primary customer service agent for the AI Developer Accelerator community. Your role is to help users with their questions and direct them to the appropriate specialized agent. # ... detailed instructions ... """, sub_agents=[policy_agent, sales_agent, course_support_agent, order_agent], tools=[get_current_time], ) ``` -------------------------------- ### Activate Virtual Environment (macOS/Linux) - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/10-sequential-agent/README.md Command to activate the Python virtual environment on macOS or Linux systems from the project root directory. This makes the ADK command and project dependencies available for use. ```Bash source ../.venv/bin/activate ``` -------------------------------- ### Agent Instruction with Session State Variables (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/5-sessions-and-state/README.md Defines the agent's instruction string, illustrating the use of template variables (e.g., {user_name}, {user_preferences}) that are automatically populated from the current session's state. ```python instruction=""" You are a helpful assistant that answers questions about the user's preferences. Here is some information about the user: Name: {user_name} Preferences: {user_preferences} """ ``` -------------------------------- ### Activate Virtual Environment (Windows PowerShell) - Bash Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/10-sequential-agent/README.md Command to activate the Python virtual environment on Windows using PowerShell, executed from the project root directory. This sets up the necessary environment variables for ADK. ```Bash ..\.venv\Scripts\Activate.ps1 ``` -------------------------------- ### Activate Virtual Environment (macOS/Linux) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/11-parallel-agent/README.md Activates the Python virtual environment for the project on macOS and Linux systems using the source command. ```bash source ../.venv/bin/activate ``` -------------------------------- ### Adding User Query to Interaction History - Python Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Demonstrates how to use the session service to add a user's input query to the interaction history, maintaining context for the conversation. ```python # Update interaction history with the user's query add_user_query_to_history( session_service, APP_NAME, USER_ID, SESSION_ID, user_input ) ``` -------------------------------- ### Configuring ADK Root Agent for Agent-as-a-Tool (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md Shows how to use the `AgentTool` wrapper to make other agents available as tools to the root agent. This allows the root agent to call sub-agents like functions and incorporate their results into its own response, maintaining control of the conversation flow. ```Python from google.adk.tools.agent_tool import AgentTool root_agent = Agent( name="manager", model="gemini-2.0-flash", description="Manager agent", instruction="You are a manager agent that uses specialized agents as tools...", tools=[ AgentTool(news_analyst), get_current_time, ], ) ``` -------------------------------- ### Setting Google API Key in .env File (.env) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Shows the format for setting the GOOGLE_API_KEY environment variable within a .env file, which is necessary for authenticating API calls to Google services used by the application. ```dotenv GOOGLE_API_KEY=your_api_key_here ``` -------------------------------- ### Activating Python Virtual Environment (macOS/Linux Bash) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Provides the standard command to activate a Python virtual environment named '.venv' located in the parent directory on macOS or Linux systems using a Bash-compatible shell. ```bash source ../.venv/bin/activate ``` -------------------------------- ### Configuring ADK Root Agent for Sub-Agent Delegation (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md Illustrates how to define a root agent (`root_agent`) that delegates tasks to specialized sub-agents. The `sub_agents` parameter lists the agent instances that the root agent can delegate to, allowing the sub-agent to take full control of the response. ```Python root_agent = Agent( name="manager", model="gemini-2.0-flash", description="Manager agent", instruction="You are a manager agent that delegates tasks to specialized agents...", sub_agents=[stock_analyst, funny_nerd], ) ``` -------------------------------- ### Importing Sub-Agents in ADK Root Agent (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md Demonstrates the required Python import statements within the root agent's `agent.py` file to make sub-agents available for use. This is a crucial step for ADK to recognize and load the sub-agents. ```Python from .sub_agents.funny_nerd.agent import funny_nerd from .sub_agents.stock_analyst.agent import stock_analyst ``` -------------------------------- ### Defining ADK Agents with AgentTool in Python Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md This snippet demonstrates how to define multiple specialized agents and wrap them as `AgentTool` instances within a root agent. This allows the root agent to delegate tasks to the specialized agents, each potentially using a different built-in tool. ```python from google.adk.tools import agent_tool search_agent = Agent( model='gemini-2.0-flash', name='SearchAgent', instruction="You're a specialist in Google Search", tools=[google_search], ) coding_agent = Agent( model='gemini-2.0-flash', name='CodeAgent', instruction="You're a specialist in Code Execution", tools=[built_in_code_execution], ) root_agent = Agent( name="RootAgent", model="gemini-2.0-flash", description="Root Agent", tools=[ agent_tool.AgentTool(agent=search_agent), agent_tool.AgentTool(agent=coding_agent) ], ) ``` -------------------------------- ### Activating Python Virtual Environment (Windows CMD) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Provides the command to activate a Python virtual environment named '.venv' located in the parent directory when using the Windows Command Prompt (CMD). ```batch ..\.venv\Scripts\activate.bat ``` -------------------------------- ### Activate Virtual Environment (Windows CMD) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/11-parallel-agent/README.md Activates the Python virtual environment for the project using the batch script on Windows Command Prompt. ```batch ..\.\venv\Scripts\activate.bat ``` -------------------------------- ### Activating Python Virtual Environment (Windows PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/8-stateful-multi-agent/README.md Provides the command to activate a Python virtual environment named '.venv' located in the parent directory when using Windows PowerShell. ```powershell ..\.venv\Scripts\Activate.ps1 ``` -------------------------------- ### Unsupported: Using Built-in Tools in ADK Sub-Agents (Python) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/7-multi-agent/README.md This code demonstrates a configuration that is currently **not supported** in ADK. It shows an attempt to define sub-agents (`search_agent`, `coding_agent`) that use built-in tools (`google_search`, `built_in_code_execution`) and then include these sub-agents in the `sub_agents` list of a root agent. Built-in tools cannot be used directly within sub-agents when employing the delegation model. ```Python search_agent = Agent( model='gemini-2.0-flash', name='SearchAgent', instruction="You're a specialist in Google Search", tools=[google_search], # Built-in tool ) coding_agent = Agent( model='gemini-2.0-flash', name='CodeAgent', instruction="You're a specialist in Code Execution", tools=[built_in_code_execution], # Built-in tool ) root_agent = Agent( name="RootAgent", model="gemini-2.0-flash", description="Root Agent", sub_agents=[ search_agent, # NOT SUPPORTED coding_agent # NOT SUPPORTED ], ) ``` -------------------------------- ### Managing ADK Sessions with Database Persistence in Python Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Shows the logic for checking if an existing session exists for a user and application, reusing it if found, or creating a new session with initial state if not. This ensures continuity across runs. ```python # Check for existing sessions for this user existing_sessions = session_service.list_sessions( app_name=APP_NAME, user_id=USER_ID, ) # If there's an existing session, use it, otherwise create a new one if existing_sessions and len(existing_sessions.sessions) > 0: # Use the most recent session SESSION_ID = existing_sessions.sessions[0].id print(f"Continuing existing session: {SESSION_ID}") else: # Create a new session with initial state session_service.create_session( app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID, state=initialize_state(), ) ``` -------------------------------- ### Activate Virtual Environment (Windows PowerShell) Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/11-parallel-agent/README.md Activates the Python virtual environment for the project using the PowerShell script on Windows PowerShell. ```powershell ..\.\venv\Scripts\Activate.ps1 ``` -------------------------------- ### Define Pydantic Output Schema for Email Content Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/4-structured-outputs/README.md Defines a Pydantic model `EmailContent` to specify the required structure for the agent's output. It includes fields for the email subject and body, along with descriptions for each field. ```python class EmailContent(BaseModel): """Schema for email content with subject and body.""" subject: str = Field( description="The subject line of the email. Should be concise and descriptive." ) body: str = Field( description="The main content of the email. Should be well-formatted with proper greeting, paragraphs, and signature." ) ``` -------------------------------- ### Updating Agent State Persistently via ADK Tool in Python Source: https://github.com/bhancockio/agent-development-kit-crash-course/blob/main/6-persistent-storage/README.md Illustrates how an agent tool can modify the session state stored in the database. Changes made to `tool_context.state` are automatically persisted by the DatabaseSessionService. ```python def add_reminder(reminder: str, tool_context: ToolContext) -> dict: # Get current reminders from state reminders = tool_context.state.get("reminders", []) # Add the new reminder reminders.append(reminder) # Update state with the new list of reminders tool_context.state["reminders"] = reminders return { "action": "add_reminder", "reminder": reminder, "message": f"Added reminder: {reminder}", } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.