import asyncio
from fiddler_otel import FiddlerClient
from fiddler_adk import GoogleADKInstrumentor
from google.adk.agents.llm_agent import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
# Set up Fiddler instrumentation
client = FiddlerClient(
api_key="YOUR_FIDDLER_API_KEY",
application_id="YOUR_APPLICATION_UUID",
url="https://your-fiddler-instance.com",
)
GoogleADKInstrumentor(client).instrument()
# Define tools
def classify_document(doc_type: str, content: str) -> dict:
"""Classify a document into a known category."""
return {"category": "Credit Memo", "confidence": 0.95}
def extract_fields(document_id: str) -> dict:
"""Extract structured fields from a document."""
return {"supplier": "McKesson", "total": "$12,450.00"}
# Create agent with tools
agent = Agent(
model="gemini-2.5-flash",
name="doc_processor",
description="Document processing assistant",
instruction="You classify and extract fields from medical documents.",
tools=[classify_document, extract_fields],
)
async def main():
session_service = InMemorySessionService()
runner = Runner(agent=agent, app_name="demo", session_service=session_service)
session = await session_service.create_session(app_name="demo", user_id="user1")
message = types.Content(
role="user",
parts=[types.Part(text="Classify this credit memo: supplier McKesson, amount $5000")],
)
async for event in runner.run_async(
user_id="user1", session_id=session.id, new_message=message
):
if hasattr(event, "content") and event.content:
parts = getattr(event.content, "parts", []) or []
text = "".join(p.text for p in parts if getattr(p, "text", None))
if text:
print(f"Agent: {text}")
# Flush traces to Fiddler before exit
client.force_flush(timeout_millis=5000)
asyncio.run(main())