Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/agents/custom-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,5 @@ if __name__ == "__main__":

```python
# Full runnable code for the StoryFlowAgent example
--8<-- "examples/python/snippets/agents/custom-agent/storyflow-agent.py"
```
--8<-- "examples/python/snippets/agents/custom-agent/storyflow_agent.py"
```
1 change: 0 additions & 1 deletion docs/agents/llm-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ capital_agent = LlmAgent(

Learn more about Tools in the [Tools](../tools/index.md) section.


## Advanced Configuration & Control

Beyond the core parameters, `LlmAgent` offers several options for finer control:
Expand Down
45 changes: 32 additions & 13 deletions docs/agents/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,36 @@ The `google-genai` library, used internally by ADK for Gemini, can connect throu
1. **Google AI Studio:**
* **Use Case:** Best for rapid prototyping and development.
* **Setup:** Typically requires an API key set as an environment variable:

```shell
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
```

* **Models:** Find available models on the [Google AI for Developers site](https://ai.google.dev/gemini-api/docs/models).

2. **Vertex AI:**
* **Use Case:** Recommended for production applications, leveraging Google Cloud infrastructure.
* **Setup:**
* Authenticate using Application Default Credentials (ADC):

```shell
gcloud auth application-default login
```

* Set your Google Cloud project and location:

```shell
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="YOUR_VERTEX_AI_LOCATION" # e.g., us-central1
```

* Explicitly tell the library to use Vertex AI:

```shell
export GOOGLE_GENAI_USE_VERTEXAI=TRUE
```

* **Models:** Find available model IDs in the [Vertex AI documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models).

**Example:**
Expand Down Expand Up @@ -92,13 +98,17 @@ To access a vast range of LLMs from providers like OpenAI, Anthropic (non-Vertex
2. **Set Provider API Keys:** Configure API keys as environment variables for the specific providers you intend to use.

* *Example for OpenAI:*

```shell
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
```

* *Example for Anthropic (non-Vertex AI):*

```shell
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
```

* *Consult the [LiteLLM Providers Documentation](https://docs.litellm.ai/docs/providers) for the correct environment variable names for other providers.*

**Example:**
Expand Down Expand Up @@ -126,7 +136,6 @@ To access a vast range of LLMs from providers like OpenAI, Anthropic (non-Vertex
)
```


## Using Open & Local Models via LiteLLM

For maximum control, cost savings, privacy, or offline use cases, you can run open-source models locally or self-host them and integrate them using LiteLLM.
Expand All @@ -141,9 +150,11 @@ For maximum control, cost savings, privacy, or offline use cases, you can run op

1. Install Ollama.
2. Pull the desired model (e.g., Google's Gemma):

```shell
ollama pull gemma:2b
```

3. Ensure the Ollama server is running (usually happens automatically after installation or by running `ollama serve`).

**Example:**
Expand All @@ -168,9 +179,9 @@ Tools like [vLLM](https://github.com/vllm-project/vllm) allow you to host models

**Setup:**

1. **Deploy Model:** Deploy your chosen model using vLLM (or a similar tool). Note the API base URL (e.g., `https://your-vllm-endpoint.run.app/v1`).
* *Important for ADK Tools:* When deploying, ensure the serving tool supports and enables OpenAI-compatible tool/function calling. For vLLM, this might involve flags like `--enable-auto-tool-choice` and potentially a specific `--tool-call-parser`, depending on the model. Refer to the vLLM documentation on Tool Use.
2. **Authentication:** Determine how your endpoint handles authentication (e.g., API key, bearer token).
1. **Deploy Model:** Deploy your chosen model using vLLM (or a similar tool). Note the API base URL (e.g., `https://your-vllm-endpoint.run.app/v1`).
* *Important for ADK Tools:* When deploying, ensure the serving tool supports and enables OpenAI-compatible tool/function calling. For vLLM, this might involve flags like `--enable-auto-tool-choice` and potentially a specific `--tool-call-parser`, depending on the model. Refer to the vLLM documentation on Tool Use.
2. **Authentication:** Determine how your endpoint handles authentication (e.g., API key, bearer token).

**Integration Example:**

Expand Down Expand Up @@ -223,16 +234,21 @@ For enterprise-grade scalability, reliability, and integration with Google Cloud

Ensure your environment is configured for Vertex AI:

1. **Authentication:** Use Application Default Credentials (ADC):
1. **Authentication:** Use Application Default Credentials (ADC):

```shell
gcloud auth application-default login
```
2. **Environment Variables:** Set your project and location:

2. **Environment Variables:** Set your project and location:

```shell
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="YOUR_ENDPOINT_LOCATION" # e.g., us-central1
```
3. **Enable Vertex Backend:** Crucially, ensure the `google-genai` library targets Vertex AI:

3. **Enable Vertex Backend:** Crucially, ensure the `google-genai` library targets Vertex AI:

```shell
export GOOGLE_GENAI_USE_VERTEXAI=TRUE
```
Expand Down Expand Up @@ -293,12 +309,15 @@ Some providers, like Anthropic, make their models available directly through Ver

**Setup:**

1. **Vertex AI Environment:** Ensure the consolidated Vertex AI setup (ADC, Env Vars, `GOOGLE_GENAI_USE_VERTEXAI=TRUE`) is complete.
2. **Install Provider Library:** Install the necessary client library configured for Vertex AI.
1. **Vertex AI Environment:** Ensure the consolidated Vertex AI setup (ADC, Env Vars, `GOOGLE_GENAI_USE_VERTEXAI=TRUE`) is complete.
2. **Install Provider Library:** Install the necessary client library configured for Vertex AI.

```shell
pip install "anthropic[vertex]"
```
3. **Register Model Class:** Add this code near the start of your application, *before* creating an agent using the Claude model string:

3. **Register Model Class:** Add this code near the start of your application, *before* creating an agent using the Claude model string:

```python
# Required for using Claude model strings directly via Vertex AI with LlmAgent
from google.adk.models.anthropic_llm import Claude
Expand Down Expand Up @@ -330,4 +349,4 @@ Some providers, like Anthropic, make their models available directly through Ver
generate_content_config=types.GenerateContentConfig(max_output_tokens=4096),
# ... other agent parameters
)
```
```
26 changes: 13 additions & 13 deletions docs/agents/multi-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ data_pipeline = SequentialAgent(
* **Structure:** A [`ParallelAgent`](workflow-agents/parallel-agents.md) runs multiple `sub_agents` concurrently, often followed by a later agent (in a `SequentialAgent`) that aggregates results.
* **Goal:** Execute independent tasks simultaneously to reduce latency, then combine their outputs.
* **ADK Primitives Used:**
* **Workflow:** `ParallelAgent` for concurrent execution (Fan-Out). Often nested within a `SequentialAgent` to handle the subsequent aggregation step (Gather).
* **Communication:** Sub-agents write results to distinct keys in **Shared Session State**. The subsequent "Gather" agent reads multiple state keys.
* **Workflow:** `ParallelAgent` for concurrent execution (Fan-Out). Often nested within a `SequentialAgent` to handle the subsequent aggregation step (Gather).
* **Communication:** Sub-agents write results to distinct keys in **Shared Session State**. The subsequent "Gather" agent reads multiple state keys.

```python
# Conceptual Code: Parallel Information Gathering
Expand Down Expand Up @@ -302,8 +302,8 @@ overall_workflow = SequentialAgent(
* **Structure:** A multi-level tree of agents where higher-level agents break down complex goals and delegate sub-tasks to lower-level agents.
* **Goal:** Solve complex problems by recursively breaking them down into simpler, executable steps.
* **ADK Primitives Used:**
* **Hierarchy:** Multi-level `parent_agent`/`sub_agents` structure.
* **Interaction:** Primarily **LLM-Driven Delegation** or **Explicit Invocation (`AgentTool`)** used by parent agents to assign tasks to children. Results are returned up the hierarchy (via tool responses or state).
* **Hierarchy:** Multi-level `parent_agent`/`sub_agents` structure.
* **Interaction:** Primarily **LLM-Driven Delegation** or **Explicit Invocation (`AgentTool`)** used by parent agents to assign tasks to children. Results are returned up the hierarchy (via tool responses or state).

```python
# Conceptual Code: Hierarchical Research Task
Expand Down Expand Up @@ -341,8 +341,8 @@ report_writer = LlmAgent(
* **Structure:** Typically involves two agents within a [`SequentialAgent`](workflow-agents/sequential-agents.md): a Generator and a Critic/Reviewer.
* **Goal:** Improve the quality or validity of generated output by having a dedicated agent review it.
* **ADK Primitives Used:**
* **Workflow:** `SequentialAgent` ensures generation happens before review.
* **Communication:** **Shared Session State** (Generator uses `output_key` to save output; Reviewer reads that state key). The Reviewer might save its feedback to another state key for subsequent steps.
* **Workflow:** `SequentialAgent` ensures generation happens before review.
* **Communication:** **Shared Session State** (Generator uses `output_key` to save output; Reviewer reads that state key). The Reviewer might save its feedback to another state key for subsequent steps.

```python
# Conceptual Code: Generator-Critic
Expand Down Expand Up @@ -419,13 +419,13 @@ refinement_loop = LoopAgent(

### Human-in-the-Loop Pattern

* **Structure:** Integrates human intervention points within an agent workflow.
* **Goal:** Allow for human oversight, approval, correction, or tasks that AI cannot perform.
* **ADK Primitives Used (Conceptual):**
* **Interaction:** Can be implemented using a custom **Tool** that pauses execution and sends a request to an external system (e.g., a UI, ticketing system) waiting for human input. The tool then returns the human's response to the agent.
* **Workflow:** Could use **LLM-Driven Delegation** (`transfer_to_agent`) targeting a conceptual "Human Agent" that triggers the external workflow, or use the custom tool within an `LlmAgent`.
* **State/Callbacks:** State can hold task details for the human; callbacks can manage the interaction flow.
* **Note:** ADK doesn't have a built-in "Human Agent" type, so this requires custom integration.
* **Structure:** Integrates human intervention points within an agent workflow.
* **Goal:** Allow for human oversight, approval, correction, or tasks that AI cannot perform.
* **ADK Primitives Used (Conceptual):**
* **Interaction:** Can be implemented using a custom **Tool** that pauses execution and sends a request to an external system (e.g., a UI, ticketing system) waiting for human input. The tool then returns the human's response to the agent.
* **Workflow:** Could use **LLM-Driven Delegation** (`transfer_to_agent`) targeting a conceptual "Human Agent" that triggers the external workflow, or use the custom tool within an `LlmAgent`.
* **State/Callbacks:** State can hold task details for the human; callbacks can manage the interaction flow.
* **Note:** ADK doesn't have a built-in "Human Agent" type, so this requires custom integration.

```python
# Conceptual Code: Using a Tool for Human Approval
Expand Down
10 changes: 5 additions & 5 deletions docs/agents/workflow-agents/parallel-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

The `ParallelAgent` is a [workflow agent](index.md) that executes its sub-agents *concurrently*. This dramatically speeds up workflows where tasks can be performed independently.

Use `ParallelAgent` when: For scenarios prioritizing speed and involving independent, resource-intensive tasks, a `ParallelAgent` facilitates efficient parallel execution. **When sub-agents operate without dependencies, their tasks can be performed concurrently**, significantly reducing overall processing time.
Use `ParallelAgent` when: For scenarios prioritizing speed and involving independent, resource-intensive tasks, a `ParallelAgent` facilitates efficient parallel execution. **When sub-agents operate without dependencies, their tasks can be performed concurrently**, significantly reducing overall processing time.

As with other [workflow agents](index.md), the `ParallelAgent` is not powered by an LLM, and is thus deterministic in how it executes. That being said, workflow agents are only concerned only with their execution (i.e. in parallel), and not their internal logic; the tools or sub-agents of a workflow agent may or may not utilize LLMs.

#### Example:
### Example

This approach is particularly beneficial for operations like multi-source data retrieval or heavy computations, where parallelization yields substantial performance gains. Importantly, this strategy assumes no inherent need for shared state or direct information exchange between the concurrently executing agents.

Expand Down Expand Up @@ -38,14 +38,14 @@ Imagine researching multiple topics simultaneously:
2. **Researcher Agent 2:** An `LlmAgent` that researches "electric vehicle technology."
3. **Researcher Agent 3:** An `LlmAgent` that researches "carbon capture methods."

```
```py
ParallelAgent(sub_agents=[ResearcherAgent1, ResearcherAgent2, ResearcherAgent3])
```

These research tasks are independent. Using a `ParallelAgent` allows them to run concurrently, potentially reducing the total research time significantly compared to running them sequentially. The results from each agent would be collected separately after they finish.

**Full code**
### Full code

```py
--8<-- "examples/python/snippets/agents/workflow-agents/parallel_agent_web_research.py"
```
```
4 changes: 2 additions & 2 deletions docs/deploy/local-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ working as intended.

The easiest way is to test your a local agent is to use the ADK CLI with `adk api_server`, which launches a local Fast API server, where you can run cURL commands to test your agent.

#### Working directory
## Working directory

First, ensure you are in the correct working directory:

Expand Down Expand Up @@ -34,7 +34,7 @@ INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```

Your server is now running locally at http://0.0.0.0:8000.
Your server is now running locally at `http://0.0.0.0:8000`.

### Creating a new session for your agent

Expand Down
13 changes: 6 additions & 7 deletions docs/get-started/quickstart-streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ To run your agent, you'll need to set up a Gemini API Key.

**.env**

```
```shell
GOOGLE_API_KEY=YOUR_API_KEY_HERE # Replace with your API Key
GOOGLE_GENAI_USE_VERTEXAI=0
```
Expand All @@ -87,13 +87,13 @@ GOOGLE_GENAI_USE_VERTEXAI=0

Now it's ready to try the agent. Run the following command to launch the **dev UI**. First, make sure to set the current directory to `app`:

```
```shell
cd app
```

Then, run the dev UI:

```
```shell
adk web
```

Expand Down Expand Up @@ -128,7 +128,7 @@ We have checked that our basic search agent works with the ADK Streaming. In the

Add `static` directory under `app`, and add `main.py` and `index.html` as empty files, as in the following structure:

```
```console
adk-streaming/ # Project folder
└── app/ # the web app folder
├── main.py # FastAPI web app
Expand Down Expand Up @@ -426,16 +426,15 @@ This HTML file sets up a basic webpage with:

1\. **Navigate to the Correct Directory:**

To run your agent effectively, you need to be in the **app folder (`adk-streaming/app`)**
To run your agent effectively, you need to be in the **app folder (`adk-streaming/app`)**

2\. **Start the Fast API**: Run the following command to start CLI interface with

```
```console
uvicorn main:app --reload
```

3\. **Access the UI:** Once the UI server starts, the terminal will display a local URL (e.g., [http://localhost:8000](http://localhost:8501)). Click this link to open the UI in your browser.


Now you should see the UI like this:

Expand Down
Loading