From 05b0c54ef3bddd691bcd829d2dbb6f34c022d6c1 Mon Sep 17 00:00:00 2001 From: sitalakshmi Date: Wed, 9 Apr 2025 10:39:29 -0400 Subject: [PATCH] add code admonitions --- docs/agents/custom-agents.md | 10 +- docs/agents/llm-agents.md | 11 +- docs/agents/workflow-agents/loop-agents.md | 8 +- .../agents/workflow-agents/parallel-agents.md | 8 +- .../workflow-agents/sequential-agents.md | 8 +- docs/callbacks/types-of-callbacks.md | 48 +-- docs/guides/responsible-agents.md | 2 +- docs/sessions/memory.md | 196 ++++++------ docs/tools/authentication.md | 281 +++++++++--------- docs/tools/function-tools.md | 36 +-- docs/tools/openapi-tools.md | 10 +- 11 files changed, 318 insertions(+), 300 deletions(-) diff --git a/docs/agents/custom-agents.md b/docs/agents/custom-agents.md index db5a875c4e..c54c066186 100644 --- a/docs/agents/custom-agents.md +++ b/docs/agents/custom-agents.md @@ -131,7 +131,9 @@ Finally, you instantiate your `StoryFlowAgent` and use the `Runner` as usual. ## Full Code Example -```python -# Full runnable code for the StoryFlowAgent example ---8<-- "examples/python/snippets/agents/custom-agent/storyflow_agent.py" -``` +???+ "Storyflow Agent" + + ```python + # Full runnable code for the StoryFlowAgent example + --8<-- "examples/python/snippets/agents/custom-agent/storyflow_agent.py" + ``` diff --git a/docs/agents/llm-agents.md b/docs/agents/llm-agents.md index 31a7fe9d1f..2830c8532e 100644 --- a/docs/agents/llm-agents.md +++ b/docs/agents/llm-agents.md @@ -166,12 +166,13 @@ For more complex reasoning involving multiple steps or executing code: ## Putting It Together: Example -Here's the complete basic `capital_agent`: +??? "Code" + Here's the complete basic `capital_agent`: -```python -# Full example code for the basic capital agent ---8<-- "examples/python/snippets/agents/llm-agent/capital_agent.py" -``` + ```python + # Full example code for the basic capital agent + --8<-- "examples/python/snippets/agents/llm-agent/capital_agent.py" + ``` _(This example demonstrates the core concepts. More complex agents might incorporate schemas, context control, planning, etc.)_ diff --git a/docs/agents/workflow-agents/loop-agents.md b/docs/agents/workflow-agents/loop-agents.md index 9b037e23d1..c537db3af9 100644 --- a/docs/agents/workflow-agents/loop-agents.md +++ b/docs/agents/workflow-agents/loop-agents.md @@ -39,8 +39,8 @@ Imagine a scenario where you want to iteratively improve a document: In this setup, the `LoopAgent` would manage the iterative process. The `CriticAgent` could be **designed to return a "STOP" signal when the document reaches a satisfactory quality level**, preventing further iterations. Alternatively, the `max_iterations` parameter could be used to limit the process to a fixed number of cycles, or external logic could be implemented to make stop decisions. The **loop would run at most five times**, ensuring the iterative refinement doesn't continue indefinitely. -#### Full code +???+ "Full Code" -```py ---8<-- "examples/python/snippets/agents/workflow-agents/loop_agent_doc_improv_agent.py" -``` + ```py + --8<-- "examples/python/snippets/agents/workflow-agents/loop_agent_doc_improv_agent.py" + ``` diff --git a/docs/agents/workflow-agents/parallel-agents.md b/docs/agents/workflow-agents/parallel-agents.md index 306ab3706c..65c03314ad 100644 --- a/docs/agents/workflow-agents/parallel-agents.md +++ b/docs/agents/workflow-agents/parallel-agents.md @@ -44,8 +44,8 @@ Imagine researching multiple topics simultaneously: 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 +???+ "Code" -```py ---8<-- "examples/python/snippets/agents/workflow-agents/parallel_agent_web_research.py" -``` + ```py + --8<-- "examples/python/snippets/agents/workflow-agents/parallel_agent_web_research.py" + ``` diff --git a/docs/agents/workflow-agents/sequential-agents.md b/docs/agents/workflow-agents/sequential-agents.md index 63f360b987..8b8f50da5d 100644 --- a/docs/agents/workflow-agents/sequential-agents.md +++ b/docs/agents/workflow-agents/sequential-agents.md @@ -37,8 +37,8 @@ SequentialAgent(sub_agents=[CodeWriterAgent, CodeReviewerAgent, CodeRefactorerAg This ensures the code is written, *then* reviewed, and *finally* refactored, in a strict, dependable order. **The output from each sub-agent is passed to the next by storing them in state via [`output_key`](../llm-agents.md)**. -#### Full code +???+ "Code" -```py ---8<-- "examples/python/snippets/agents/workflow-agents/sequential-agent-code-development-agent.py" -``` + ```py + --8<-- "examples/python/snippets/agents/workflow-agents/sequential_agent_code_development_agent.py" + ``` diff --git a/docs/callbacks/types-of-callbacks.md b/docs/callbacks/types-of-callbacks.md index acb7ba975f..b74acbfcf4 100644 --- a/docs/callbacks/types-of-callbacks.md +++ b/docs/callbacks/types-of-callbacks.md @@ -12,9 +12,11 @@ These callbacks are available on *any* agent that inherits from `BaseAgent` (inc **Purpose:** Ideal for setting up resources or state needed only for this specific agent's run, performing validation checks on the session state (callback\_context.state) before execution starts, logging the entry point of the agent's activity, or potentially modifying the invocation context before the core logic uses it. -```py ---8<-- "examples/python/snippets/callbacks/before_agent_callback.py" -``` +??? "Code" + + ```py + --8<-- "examples/python/snippets/callbacks/before_agent_callback.py" + ``` ### After Agent Callback @@ -22,9 +24,11 @@ These callbacks are available on *any* agent that inherits from `BaseAgent` (inc **Purpose:** Useful for cleanup tasks, post-execution validation, logging the completion of an agent's activity, modifying final state, or augmenting/replacing the agent's final output. -```py ---8<-- "examples/python/snippets/callbacks/after_agent_callback.py" -``` +??? "Code" + + ```py + --8<-- "examples/python/snippets/callbacks/after_agent_callback.py" + ``` ## LLM Interaction Callbacks @@ -39,9 +43,11 @@ These callbacks are specific to `LlmAgent` and provide hooks around the interact **Return Value Effect:** If the callback returns `None`, the LLM continues its normal workflow. If the callback returns an `LlmResponse` object, then the call to the LLM is **skipped**. The returned `LlmResponse` is used directly as if it came from the model. This is powerful for implementing guardrails or caching. -```py ---8<-- "examples/python/snippets/callbacks/before_model_callback.py" -``` +??? "Code" + + ```py + --8<-- "examples/python/snippets/callbacks/before_model_callback.py" + ``` ### After Model Callback @@ -55,9 +61,11 @@ If the callback returns `None`, the LLM continues its normal workflow. If the ca * parsing structured data from the LLM response and storing it in `callback_context.state` * or handling specific error codes. -```py ---8<-- "examples/python/snippets/callbacks/after_model_callback.py" -``` +??? "Code" + + ```py + --8<-- "examples/python/snippets/callbacks/after_model_callback.py" + ``` ## Tool Execution Callbacks @@ -74,9 +82,11 @@ These callbacks are also specific to `LlmAgent` and trigger around the execution 1. If the callback returns `None`, the tool's `run_async` method is executed with the (potentially modified) `args`. 2. If a dictionary is returned, the tool's `run_async` method is **skipped**. The returned dictionary is used directly as the result of the tool call. This is useful for caching or overriding tool behavior. -```py ---8<-- "examples/python/snippets/callbacks/before_tool_callback.py" -``` +??? "Code" + + ```py + --8<-- "examples/python/snippets/callbacks/before_tool_callback.py" + ``` ### After Tool Callback @@ -89,6 +99,8 @@ These callbacks are also specific to `LlmAgent` and trigger around the execution 1. If the callback returns `None`, the original `tool_response` is used. 2. If a new dictionary is returned, it **replaces** the original `tool_response`. This allows modifying or filtering the result seen by the LLM. -```py ---8<-- "examples/python/snippets/callbacks/after_tool_callback.py" -``` \ No newline at end of file +??? "Code" + + ```py + --8<-- "examples/python/snippets/callbacks/after_tool_callback.py" + ``` \ No newline at end of file diff --git a/docs/guides/responsible-agents.md b/docs/guides/responsible-agents.md index aa0d81df6a..40f15ea755 100644 --- a/docs/guides/responsible-agents.md +++ b/docs/guides/responsible-agents.md @@ -208,7 +208,7 @@ If none of these options satisfy your requirements, you can build your own code ### Evaluations -See [Evaluate Agents](../guides/evaluate-agents.md). +See [Evaluate Agents](../evaluate/index.md). ### VPC-SC Perimeters and Network Controls diff --git a/docs/sessions/memory.md b/docs/sessions/memory.md index 620338a9e6..432e1a887f 100644 --- a/docs/sessions/memory.md +++ b/docs/sessions/memory.md @@ -71,100 +71,102 @@ The typical workflow involves these steps: This example demonstrates the basic flow using the `InMemory` services for simplicity. -```py -import asyncio -from google.adk.agents import LlmAgent -from google.adk.sessions import InMemorySessionService, Session -from google.adk.memory import InMemoryMemoryService # Import MemoryService -from google.adk.runners import Runner -from google.adk.tools import load_memory # Tool to query memory -from google.genai.types import Content, Part - -# --- Constants --- -APP_NAME = "memory_example_app" -USER_ID = "mem_user" -MODEL = "gemini-2.0-flash-exp" # Use a valid model - -# --- Agent Definitions --- -# Agent 1: Simple agent to capture information -info_capture_agent = LlmAgent( - model=MODEL, - name="InfoCaptureAgent", - instruction="Acknowledge the user's statement.", - # output_key="captured_info" # Could optionally save to state too -) - -# Agent 2: Agent that can use memory -memory_recall_agent = LlmAgent( - model=MODEL, - name="MemoryRecallAgent", - instruction="Answer the user's question. Use the 'load_memory' tool " - "if the answer might be in past conversations.", - tools=[load_memory] # Give the agent the tool -) - -# --- Services and Runner --- -session_service = InMemorySessionService() -memory_service = InMemoryMemoryService() # Use in-memory for demo - -runner = Runner( - # Start with the info capture agent - agent=info_capture_agent, - app_name=APP_NAME, - session_service=session_service, - memory_service=memory_service # Provide the memory service to the Runner -) - -# --- Scenario --- - -# Turn 1: Capture some information in a session -print("--- Turn 1: Capturing Information ---") -session1_id = "session_info" -session1 = session_service.create_session(APP_NAME, USER_ID, session1_id) -user_input1 = Content(parts=[Part(text="My favorite project is Project Alpha.")]) - -# Run the agent -final_response_text = "(No final response)" -for event in runner.run(USER_ID, session1_id, user_input1): - if event.is_final_response() and event.content and event.content.parts: - final_response_text = event.content.parts[0].text -print(f"Agent 1 Response: {final_response_text}") - -# Get the completed session -completed_session1 = session_service.get_session(APP_NAME, USER_ID, session1_id) - -# Add this session's content to the Memory Service -print("\n--- Adding Session 1 to Memory ---") -memory_service.add_session_to_memory(completed_session1) -print("Session added to memory.") - -# Turn 2: In a *new* (or same) session, ask a question requiring memory -print("\n--- Turn 2: Recalling Information ---") -session2_id = "session_recall" # Can be same or different session ID -session2 = session_service.create_session(APP_NAME, USER_ID, session2_id) - -# Switch runner to the recall agent -runner.agent = memory_recall_agent -user_input2 = Content(parts=[Part(text="What is my favorite project?")]) - -# Run the recall agent -print("Running MemoryRecallAgent...") -final_response_text_2 = "(No final response)" -for event in runner.run(USER_ID, session2_id, user_input2): - print(f" Event: {event.author} - Type: {'Text' if event.content and event.content.parts and event.content.parts[0].text else ''}" - f"{'FuncCall' if event.get_function_calls() else ''}" - f"{'FuncResp' if event.get_function_responses() else ''}") - if event.is_final_response() and event.content and event.content.parts: - final_response_text_2 = event.content.parts[0].text - print(f"Agent 2 Final Response: {final_response_text_2}") - break # Stop after final response - -# Expected Event Sequence for Turn 2: -# 1. User sends "What is my favorite project?" -# 2. Agent (LLM) decides to call `load_memory` tool with a query like "favorite project". -# 3. Runner executes the `load_memory` tool, which calls `memory_service.search_memory`. -# 4. `InMemoryMemoryService` finds the relevant text ("My favorite project is Project Alpha.") from session1. -# 5. Tool returns this text in a FunctionResponse event. -# 6. Agent (LLM) receives the function response, processes the retrieved text. -# 7. Agent generates the final answer (e.g., "Your favorite project is Project Alpha."). -``` +???+ "Full Code" + + ```py + import asyncio + from google.adk.agents import LlmAgent + from google.adk.sessions import InMemorySessionService, Session + from google.adk.memory import InMemoryMemoryService # Import MemoryService + from google.adk.runners import Runner + from google.adk.tools import load_memory # Tool to query memory + from google.genai.types import Content, Part + + # --- Constants --- + APP_NAME = "memory_example_app" + USER_ID = "mem_user" + MODEL = "gemini-2.0-flash-exp" # Use a valid model + + # --- Agent Definitions --- + # Agent 1: Simple agent to capture information + info_capture_agent = LlmAgent( + model=MODEL, + name="InfoCaptureAgent", + instruction="Acknowledge the user's statement.", + # output_key="captured_info" # Could optionally save to state too + ) + + # Agent 2: Agent that can use memory + memory_recall_agent = LlmAgent( + model=MODEL, + name="MemoryRecallAgent", + instruction="Answer the user's question. Use the 'load_memory' tool " + "if the answer might be in past conversations.", + tools=[load_memory] # Give the agent the tool + ) + + # --- Services and Runner --- + session_service = InMemorySessionService() + memory_service = InMemoryMemoryService() # Use in-memory for demo + + runner = Runner( + # Start with the info capture agent + agent=info_capture_agent, + app_name=APP_NAME, + session_service=session_service, + memory_service=memory_service # Provide the memory service to the Runner + ) + + # --- Scenario --- + + # Turn 1: Capture some information in a session + print("--- Turn 1: Capturing Information ---") + session1_id = "session_info" + session1 = session_service.create_session(APP_NAME, USER_ID, session1_id) + user_input1 = Content(parts=[Part(text="My favorite project is Project Alpha.")]) + + # Run the agent + final_response_text = "(No final response)" + for event in runner.run(USER_ID, session1_id, user_input1): + if event.is_final_response() and event.content and event.content.parts: + final_response_text = event.content.parts[0].text + print(f"Agent 1 Response: {final_response_text}") + + # Get the completed session + completed_session1 = session_service.get_session(APP_NAME, USER_ID, session1_id) + + # Add this session's content to the Memory Service + print("\n--- Adding Session 1 to Memory ---") + memory_service.add_session_to_memory(completed_session1) + print("Session added to memory.") + + # Turn 2: In a *new* (or same) session, ask a question requiring memory + print("\n--- Turn 2: Recalling Information ---") + session2_id = "session_recall" # Can be same or different session ID + session2 = session_service.create_session(APP_NAME, USER_ID, session2_id) + + # Switch runner to the recall agent + runner.agent = memory_recall_agent + user_input2 = Content(parts=[Part(text="What is my favorite project?")]) + + # Run the recall agent + print("Running MemoryRecallAgent...") + final_response_text_2 = "(No final response)" + for event in runner.run(USER_ID, session2_id, user_input2): + print(f" Event: {event.author} - Type: {'Text' if event.content and event.content.parts and event.content.parts[0].text else ''}" + f"{'FuncCall' if event.get_function_calls() else ''}" + f"{'FuncResp' if event.get_function_responses() else ''}") + if event.is_final_response() and event.content and event.content.parts: + final_response_text_2 = event.content.parts[0].text + print(f"Agent 2 Final Response: {final_response_text_2}") + break # Stop after final response + + # Expected Event Sequence for Turn 2: + # 1. User sends "What is my favorite project?" + # 2. Agent (LLM) decides to call `load_memory` tool with a query like "favorite project". + # 3. Runner executes the `load_memory` tool, which calls `memory_service.search_memory`. + # 4. `InMemoryMemoryService` finds the relevant text ("My favorite project is Project Alpha.") from session1. + # 5. Tool returns this text in a FunctionResponse event. + # 6. Agent (LLM) receives the function response, processes the retrieved text. + # 7. Agent generates the final answer (e.g., "Your favorite project is Project Alpha."). + ``` diff --git a/docs/tools/authentication.md b/docs/tools/authentication.md index 4d4f087d0c..d3a49b21d2 100644 --- a/docs/tools/authentication.md +++ b/docs/tools/authentication.md @@ -510,144 +510,143 @@ except Exception as e: ``` -## Full Code - -=== "Tools and Agent" - - ```py title="tools_and_agent.py" - --8<-- "examples/python/snippets/tools/auth/agent_cli.py" - ``` -=== "Agent CLI" - - ```py title="agent_cli.py" - --8<-- "examples/python/snippets/tools/auth/agent_cli.py" - ``` -=== "Helper" - - ```py title="helpers.py" - --8<-- "examples/python/snippets/tools/auth/helpers.py" - ``` -=== "Spec" - - ```yaml - openapi: 3.0.1 - info: - title: Okta User Info API - version: 1.0.0 - description: |- - API to retrieve user profile information based on a valid Okta OIDC Access Token. - Authentication is handled via OpenID Connect with Okta. - contact: - name: API Support - email: support@example.com # Replace with actual contact if available - servers: - - url: - description: Production Environment - paths: - /okta-jwt-user-api: - get: - summary: Get Authenticated User Info - description: |- - Fetches profile details for the user - operationId: getUserInfo - tags: - - User Profile - security: - - okta_oidc: - - openid - - email - - profile - responses: - '200': - description: Successfully retrieved user information. - content: - application/json: - schema: - type: object - properties: - sub: - type: string - description: Subject identifier for the user. - example: "abcdefg" - name: - type: string - description: Full name of the user. - example: "Example LastName" - locale: - type: string - description: User's locale, e.g., en-US or en_US. - example: "en_US" - email: - type: string - format: email - description: User's primary email address. - example: "username@example.com" - preferred_username: - type: string - description: Preferred username of the user (often the email). - example: "username@example.com" - given_name: - type: string - description: Given name (first name) of the user. - example: "Example" - family_name: - type: string - description: Family name (last name) of the user. - example: "LastName" - zoneinfo: - type: string - description: User's timezone, e.g., America/Los_Angeles. - example: "America/Los_Angeles" - updated_at: - type: integer - format: int64 # Using int64 for Unix timestamp - description: Timestamp when the user's profile was last updated (Unix epoch time). - example: 1743617719 - email_verified: - type: boolean - description: Indicates if the user's email address has been verified. - example: true - required: - - sub - - name - - locale - - email - - preferred_username - - given_name - - family_name - - zoneinfo - - updated_at - - email_verified - '401': - description: Unauthorized. The provided Bearer token is missing, invalid, or expired. - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - '403': - description: Forbidden. The provided token does not have the required scopes or permissions to access this resource. - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - components: - securitySchemes: - okta_oidc: - type: openIdConnect - description: Authentication via Okta using OpenID Connect. Requires a Bearer Access Token. - openIdConnectUrl: https://your-endpoint.okta.com/.well-known/openid-configuration - - schemas: - Error: - type: object - properties: - code: - type: string - description: An error code. - message: - type: string - description: A human-readable error message. - required: - - code - - message - ``` +??? "Full Code" + + === "Tools and Agent" + + ```py title="tools_and_agent.py" + --8<-- "examples/python/snippets/tools/auth/agent_cli.py" + ``` + === "Agent CLI" + + ```py title="agent_cli.py" + --8<-- "examples/python/snippets/tools/auth/agent_cli.py" + ``` + === "Helper" + + ```py title="helpers.py" + --8<-- "examples/python/snippets/tools/auth/helpers.py" + ``` + === "Spec" + + ```yaml + openapi: 3.0.1 + info: + title: Okta User Info API + version: 1.0.0 + description: |- + API to retrieve user profile information based on a valid Okta OIDC Access Token. + Authentication is handled via OpenID Connect with Okta. + contact: + name: API Support + email: support@example.com # Replace with actual contact if available + servers: + - url: + description: Production Environment + paths: + /okta-jwt-user-api: + get: + summary: Get Authenticated User Info + description: |- + Fetches profile details for the user + operationId: getUserInfo + tags: + - User Profile + security: + - okta_oidc: + - openid + - email + - profile + responses: + '200': + description: Successfully retrieved user information. + content: + application/json: + schema: + type: object + properties: + sub: + type: string + description: Subject identifier for the user. + example: "abcdefg" + name: + type: string + description: Full name of the user. + example: "Example LastName" + locale: + type: string + description: User's locale, e.g., en-US or en_US. + example: "en_US" + email: + type: string + format: email + description: User's primary email address. + example: "username@example.com" + preferred_username: + type: string + description: Preferred username of the user (often the email). + example: "username@example.com" + given_name: + type: string + description: Given name (first name) of the user. + example: "Example" + family_name: + type: string + description: Family name (last name) of the user. + example: "LastName" + zoneinfo: + type: string + description: User's timezone, e.g., America/Los_Angeles. + example: "America/Los_Angeles" + updated_at: + type: integer + format: int64 # Using int64 for Unix timestamp + description: Timestamp when the user's profile was last updated (Unix epoch time). + example: 1743617719 + email_verified: + type: boolean + description: Indicates if the user's email address has been verified. + example: true + required: + - sub + - name + - locale + - email + - preferred_username + - given_name + - family_name + - zoneinfo + - updated_at + - email_verified + '401': + description: Unauthorized. The provided Bearer token is missing, invalid, or expired. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '403': + description: Forbidden. The provided token does not have the required scopes or permissions to access this resource. + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + components: + securitySchemes: + okta_oidc: + type: openIdConnect + description: Authentication via Okta using OpenID Connect. Requires a Bearer Access Token. + openIdConnectUrl: https://your-endpoint.okta.com/.well-known/openid-configuration + schemas: + Error: + type: object + properties: + code: + type: string + description: An error code. + message: + type: string + description: A human-readable error message. + required: + - code + - message + ``` diff --git a/docs/tools/function-tools.md b/docs/tools/function-tools.md index e6cf402e07..db2da680a6 100644 --- a/docs/tools/function-tools.md +++ b/docs/tools/function-tools.md @@ -30,21 +30,21 @@ Strive to make your return values as descriptive as possible. *For example,* ins The docstring of your function serves as the tool's description and is sent to the LLM. Therefore, a well-written and comprehensive docstring is crucial for the LLM to understand how to use the tool effectively. Clearly explain the purpose of the function, the meaning of its parameters, and the expected return values. -### Example +??? "Example" -This tool is a python function which obtains the Stock price of a given Stock ticker/ symbol. + This tool is a python function which obtains the Stock price of a given Stock ticker/ symbol. -Note: You need to `pip install yfinance` library before using this tool. + Note: You need to `pip install yfinance` library before using this tool. -```py ---8<-- "examples/python/snippets/tools/function-tools/func_tool.py" -``` + ```py + --8<-- "examples/python/snippets/tools/function-tools/func_tool.py" + ``` -The return value from this tool will be wrapped into a dictionary. + The return value from this tool will be wrapped into a dictionary. -```json -{"result": "$123"} -``` + ```json + {"result": "$123"} + ``` ### Best Practices @@ -110,11 +110,11 @@ Each value you yield is packaged into a FunctionResponse by the framework and se The Python object your generator function returns is considered the final result of the tool execution. The framework packages this value (even if it's None) into the content of the final `FunctionResponse` sent back to the LLM, indicating the tool execution is complete. -### Example: File Processing Simulation +??? "Example: File Processing Simulation" -```py ---8<-- "examples/python/snippets/tools/function-tools/file_processor.py" -``` + ```py + --8<-- "examples/python/snippets/tools/function-tools/file_processor.py" + ``` #### Key aspects of this example @@ -152,11 +152,11 @@ The `AgentTool` class provides the following attributes for customizing its beha * **skip\_summarization: bool:** If set to True, the framework will **bypass the LLM-based summarization** of the tool agent's response. This can be useful when the tool's response is already well-formatted and requires no further processing. -### Example +??? "Example" -```py ---8<-- "examples/python/snippets/tools/function-tools/summarizer.py" -``` + ```py + --8<-- "examples/python/snippets/tools/function-tools/summarizer.py" + ``` ### How it works diff --git a/docs/tools/openapi-tools.md b/docs/tools/openapi-tools.md index efcd7d470c..f7de5ee564 100644 --- a/docs/tools/openapi-tools.md +++ b/docs/tools/openapi-tools.md @@ -79,10 +79,12 @@ Follow these steps to integrate an OpenAPI spec into your agent: 5. **Instruct Agent**: Update your agent's instructions to inform it about the new API capabilities and the names of the tools it can use (e.g., `list_pets`, `create_pet`). The tool descriptions generated from the spec will also help the LLM. 6. **Run Agent**: Execute your agent using the `Runner`. When the LLM determines it needs to call one of the APIs, it will generate a function call targeting the appropriate `RestApiTool`, which will then handle the HTTP request automatically. -## Code Example: Pet Store API +## Example This example demonstrates generating tools from a simple Pet Store OpenAPI spec (using `httpbin.org` for mock responses) and interacting with them via an agent. -```python title="openapi_example.py" ---8<-- "examples/python/snippets/tools/openapi_tool.py" -``` +???+ "Code: Pet Store API" + + ```python title="openapi_example.py" + --8<-- "examples/python/snippets/tools/openapi_tool.py" + ```