AgentSDK
Examples
Practical examples for common use cases.
Basic Examples
Email Management
Copy
Ask AI
from observee_agents import chat_with_tools
# Check and summarize emails
result = chat_with_tools(
message="Check my Gmail inbox and summarize important emails from today",
provider="anthropic"
)
print(result["content"])
YouTube Content Analysis
Copy
Ask AI
# Get video transcript and analyze
result = chat_with_tools(
message="Get the transcript from this YouTube video and create a summary: https://youtube.com/watch?v=example",
provider="openai"
)
print(result["content"])
Project Management
Copy
Ask AI
# Create Linear issue
result = chat_with_tools(
message="Create a Linear issue titled 'Fix login bug' with description 'Users cannot login with Google OAuth'",
provider="gemini"
)
print(result["content"])
Web Search
Copy
Ask AI
# Search and analyze
result = chat_with_tools(
message="Search for the latest Python 3.12 features and explain the most important ones",
provider="anthropic"
)
print(result["content"])
Advanced Examples
Multi-Step Workflow
Copy
Ask AI
# Step 1: Research
research = chat_with_tools(
message="Search for recent AI agent developments",
provider="anthropic"
)
# Step 2: Create content based on research
content = chat_with_tools(
message=f"Based on this research: {research['content']}, create a LinkedIn post about AI agents",
provider="openai"
)
print(content["content"])
Tool Chaining
Copy
Ask AI
# Get YouTube transcript, then create Linear issue
result = chat_with_tools(
message="Get the transcript from this video https://youtube.com/watch?v=example and create a Linear issue with the key points",
provider="anthropic"
)
print(result["content"])
Content Creation Pipeline
Copy
Ask AI
# Research -> Write -> Organize
pipeline_result = chat_with_tools(
message="Search for Python best practices, write a summary, and create a Google Doc with the findings",
provider="openai"
)
print(pipeline_result["content"])
Streaming Examples
Real-time Chat
Copy
Ask AI
import asyncio
from observee_agents import chat_with_tools_stream
async def ai_assistant():
print("AI Assistant (type 'quit' to exit)")
while True:
user_input = input("\n👤 You: ")
if user_input.lower() == 'quit':
break
print("🤖 AI: ", end="")
async for chunk in chat_with_tools_stream(
message=user_input,
provider="anthropic"
):
if chunk["type"] == "content":
print(chunk["content"], end="", flush=True)
elif chunk["type"] == "tool_result":
print(f"\n🔧 [Used: {chunk['tool_name']}]")
print("🤖 AI: ", end="")
print()
asyncio.run(ai_assistant())
Progress Tracking
Copy
Ask AI
import asyncio
async def track_progress():
print("Processing your request...")
async for chunk in chat_with_tools_stream(
message="Search for recent news, summarize it, and create a Slack message",
provider="anthropic"
):
if chunk["type"] == "tool_result":
print(f"✅ Completed: {chunk['tool_name']}")
elif chunk["type"] == "content":
print(chunk["content"], end="")
asyncio.run(track_progress())
Tool-Specific Examples
Direct Tool Execution
Copy
Ask AI
from observee_agents import execute_tool
# Get YouTube transcript directly
transcript = execute_tool(
tool_name="youtube_get_transcript",
tool_input={"video_url": "https://youtube.com/watch?v=example"}
)
# Search web directly
search_results = execute_tool(
tool_name="brave_search",
tool_input={"query": "Python 3.12 features"}
)
# Create Linear issue directly
issue = execute_tool(
tool_name="linear_create_issue",
tool_input={
"title": "New Feature Request",
"description": "Add dark mode support"
}
)
Tool Discovery
Copy
Ask AI
from observee_agents import filter_tools
# Find tools for specific tasks
productivity_tools = filter_tools(
query="productivity task management",
max_tools=5
)
for tool in productivity_tools:
print(f"📋 {tool['name']}: {tool['description']}")
# Find communication tools
comm_tools = filter_tools(
query="communication messaging slack email",
max_tools=3
)
for tool in comm_tools:
print(f"💬 {tool['name']}: {tool['description']}")
Provider Comparison
Copy
Ask AI
# Test same query across providers
query = "Explain quantum computing in simple terms"
providers = ["anthropic", "openai", "gemini"]
results = {}
for provider in providers:
results[provider] = chat_with_tools(
message=query,
provider=provider
)
# Compare responses
for provider, result in results.items():
print(f"\n--- {provider.upper()} ---")
print(result["content"][:200] + "...")
print(f"Tools used: {len(result['tool_calls'])}")
Error Handling Examples
Graceful Degradation
Copy
Ask AI
def safe_chat(message, preferred_provider="anthropic"):
providers = [preferred_provider, "openai", "gemini"]
for provider in providers:
try:
result = chat_with_tools(
message=message,
provider=provider
)
return result
except Exception as e:
print(f"Failed with {provider}: {e}")
continue
return {"content": "All providers failed", "tool_calls": []}
# Usage
result = safe_chat("What's the weather like?", "anthropic")
Retry Logic
Copy
Ask AI
import time
def retry_chat(message, max_retries=3):
for attempt in range(max_retries):
try:
return chat_with_tools(
message=message,
provider="anthropic"
)
except Exception as e:
if attempt == max_retries - 1:
raise e
print(f"Attempt {attempt + 1} failed: {e}")
time.sleep(2 ** attempt) # Exponential backoff
# Usage
result = retry_chat("Search for recent news")
Configuration Examples
Development vs Production
Copy
Ask AI
import os
def get_config():
if os.getenv("ENVIRONMENT") == "development":
return {
"sync_tools": True,
"enable_filtering": False,
"max_tools": 50
}
else:
return {
"sync_tools": False,
"enable_filtering": True,
"filter_type": "bm25",
"max_tools": 10
}
config = get_config()
result = chat_with_tools(
message="Test query",
provider="anthropic",
**config
)
Custom Filtering
Copy
Ask AI
# Fast keyword search
fast_result = chat_with_tools(
message="Gmail email management",
filter_type="bm25",
max_tools=5
)
# Semantic search
semantic_result = chat_with_tools(
message="Help me be more productive",
filter_type="local_embedding",
max_tools=10
)
# High accuracy search (requires cloud dependencies)
accurate_result = chat_with_tools(
message="Complex analytical task",
filter_type="cloud",
max_tools=15
)
Next Steps
Was this page helpful?
On this page
- Basic Examples
- Email Management
- YouTube Content Analysis
- Project Management
- Web Search
- Advanced Examples
- Multi-Step Workflow
- Tool Chaining
- Content Creation Pipeline
- Streaming Examples
- Real-time Chat
- Progress Tracking
- Tool-Specific Examples
- Direct Tool Execution
- Tool Discovery
- Provider Comparison
- Error Handling Examples
- Graceful Degradation
- Retry Logic
- Configuration Examples
- Development vs Production
- Custom Filtering
- Next Steps
Assistant
Responses are generated using AI and may contain mistakes.