import asyncio
from observee_agents import chat_with_tools_stream, get_conversation_history
async def conversational_streaming():
session_id = "streaming_assistant"
custom_prompt = "You are a helpful assistant. Stream responses naturally."
print("💬 First streaming message:")
async for chunk in chat_with_tools_stream(
message="Search for emails about meetings",
provider="anthropic",
session_id=session_id, # 🆕 Session for memory
system_prompt=custom_prompt, # 🆕 Custom system prompt
observee_api_key=os.getenv("OBSERVEE_API_KEY")
):
if chunk["type"] == "content":
print(chunk["content"], end="", flush=True)
elif chunk["type"] == "tool_result":
print(f"\n🔧 [Tool: {chunk['tool_name']}]")
elif chunk["type"] == "done":
print(f"\n✅ Session: {chunk.get('session_id')}")
print("\n" + "="*40 + "\n💬 Follow-up streaming (remembers context):")
async for chunk in chat_with_tools_stream(
message="What was the subject of the first meeting?",
session_id=session_id, # Same session = memory!
observee_api_key=os.getenv("OBSERVEE_API_KEY")
):
if chunk["type"] == "content":
print(chunk["content"], end="", flush=True)
elif chunk["type"] == "final_content":
print(chunk["content"], end="", flush=True)
# Check conversation history
history = get_conversation_history(session_id)
print(f"\n📊 Total messages in conversation: {len(history)}")
asyncio.run(conversational_streaming())