from upsonic import Agent, Task
from pydantic import BaseModel
class ReportResult(BaseModel):
title: str
summary: str
key_points: list[str]
confidence: float
# Create and execute task
agent = Agent(model="anthropic/claude-sonnet-4-5", name="Analysis Agent")
task = Task(
description="Generate a market analysis report",
response_format=ReportResult,
enable_cache=True
)
result = agent.print_do(task)
# Access all available information
print("=== TASK EXECUTION SUMMARY ===")
print(f"Task ID: {task.get_task_id()}")
if task.start_time and task.end_time:
print(f"Wall-clock: {(task.end_time - task.start_time):.2f} seconds")
u = task.usage
if u.cost is not None:
print(f"Cost: ${u.cost:.6f}")
print(f"Tokens: {u.input_tokens} in, {u.output_tokens} out")
print(f"Tool calls: {len(task.tool_calls)}")
print(f"Cache hit: {task.cache_hit}")
print("\n=== TASK RESULT ===")
print(f"Result: {result}")
print(f"Response type: {type(task.response)}")
print("\n=== CACHE STATISTICS ===")
cache_stats = task.get_cache_stats()
for key, value in cache_stats.items():
print(f"{key}: {value}")