> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google ADK

> Trace Google Agent Development Kit (ADK) workflows with Netra auto-instrumentation. Monitor agent execution, tool calls, and state across ADK apps.

<img src="https://mintcdn.com/netra/u6ajHWd7ki_9CRWQ/images/integration-logos/ai-frameworks/agent-dev-kit.png?fit=max&auto=format&n=u6ajHWd7ki_9CRWQ&q=85&s=5f6985e586fafaa3e8b18ee145a8d13e" alt="Google ADK" width="178" height="80" data-path="images/integration-logos/ai-frameworks/agent-dev-kit.png" />

## Installation

Install both the Netra SDK and Google ADK:

<CodeGroup>
  ```bash Python theme={null}
  pip install netra-sdk google-adk
  ```
</CodeGroup>

## Usage

Initialize the Netra SDK to automatically trace all Google ADK operations:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  from google.adk import Agent
  import os

  # Initialize Netra
  Netra.init(
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      trace_content=True
  )

  # Define agent - automatically traced
  agent = Agent(
      name="assistant",
      model="gemini-1.5-pro",
      instructions="You are a helpful assistant"
  )

  # Run agent
  response = await agent.run("What is Google ADK?")
  print(response.output)
  ```
</CodeGroup>

### Getting Started

Trace basic agent execution:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import task
  from netra import SpanWrapper
  from google.adk import Agent

  @task()
  async def run_agent(prompt: str) -> str:
      span = SpanWrapper("adk-agent", {
          "prompt": prompt
      }).start()
      
      agent = Agent(
          name="assistant",
          model="gemini-1.5-pro",
          instructions="You are a helpful assistant"
      )
      
      response = await agent.run(prompt)
      
      span.set_attribute("response", response.output)
      span.end()
      
      return response.output
  ```
</CodeGroup>

### Agent Tools

Trace agents with custom tools:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import agent
  from netra import SpanWrapper
  from google.adk import Agent, Tool

  def get_weather(location: str) -> str:
      """Get weather information for a location."""
      return f"Weather in {location}: Sunny, 72°F"

  @agent()
  async def agent_with_tools(query: str):
      tool_span = SpanWrapper("adk-agent-tools", {
          "query": query
      }).start()
      
      # Define tool
      weather_tool = Tool(
          name="get_weather",
          description="Get weather information",
          function=get_weather
      )
      
      # Create agent with tool
      assistant = Agent(
          name="weather-agent",
          model="gemini-1.5-pro",
          instructions="Help users with weather information",
          tools=[weather_tool]
      )
      
      response = await assistant.run(query)
      tool_span.set_attribute("response", response.output)
      tool_span.end()
      
      return response.output
  ```
</CodeGroup>

### Multi-Agent Systems

Trace multi-agent orchestration:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import workflow
  from netra import SpanWrapper
  from google.adk import Agent

  @workflow()
  async def multi_agent_system(task: str):
      workflow_span = SpanWrapper("multi-agent-workflow", {
          "task": task
      }).start()
      
      # Research agent
      researcher = Agent(
          name="researcher",
          model="gemini-1.5-pro",
          instructions="Research and gather information"
      )
      
      # Writer agent
      writer = Agent(
          name="writer",
          model="gemini-1.5-pro",
          instructions="Write based on research"
      )
      
      # Execute agents in sequence
      research_result = await researcher.run(f"Research: {task}")
      final_result = await writer.run(
          f"Write based on: {research_result.output}"
      )
      
      workflow_span.set_attribute("result", final_result.output)
      workflow_span.end()
      
      return final_result.output
  ```
</CodeGroup>

### Streaming Responses

Trace streaming agent outputs:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import task
  from netra import SpanWrapper

  @task()
  async def stream_agent_response(prompt: str):
      stream_span = SpanWrapper("adk-stream").start()
      
      agent = Agent(
          name="assistant",
          model="gemini-1.5-pro",
          instructions="You are a helpful assistant"
      )
      
      full_response = ""
      async for chunk in agent.stream(prompt):
          print(chunk, end='', flush=True)
          full_response += chunk
      
      stream_span.set_attribute("response", full_response)
      stream_span.end()
      
      return full_response
  ```
</CodeGroup>

### State Management

Trace agents with persistent state:

<CodeGroup>
  ```python Python theme={null}
  from netra.decorators import agent
  from netra import SpanWrapper
  from google.adk import Agent, Memory

  @agent()
  async def stateful_agent(user_id: str, message: str):
      state_span = SpanWrapper("adk-stateful", {
          "user_id": user_id,
          "message": message
      }).start()
      
      # Create agent with memory
      assistant = Agent(
          name="assistant",
          model="gemini-1.5-pro",
          instructions="Remember context from previous interactions",
          memory=Memory(user_id=user_id)
      )
      
      response = await assistant.run(message)
      state_span.set_attribute("response", response.output)
      state_span.end()
      
      return response.output
  ```
</CodeGroup>

## Configuration

Configure selective instrumentation:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  from netra.instrumentation.instruments import InstrumentSet

  # Enable Google ADK instrumentation
  Netra.init(
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      trace_content=True,
      instruments={InstrumentSet.ADK}
  )
  ```
</CodeGroup>

## Next Steps

* [Quick Start Guide](https://docs.getnetra.ai/quick-start/python) - Complete setup and configuration
* [Decorators](https://docs.getnetra.ai/tracing/decorators) - Add custom tracing with `@workflow`, `@agent`, and `@task` decorators
* [Google ADK Documentation](https://google.github.io/adk-docs/) - Official Google ADK documentation
