import asyncio
from pilottai import Serve
from pilottai.core import AgentConfig, LLMConfig
from pilottai.memory import EnhancedMemory
async def memory_example():
# Initialize PilottAI
pilott = Serve(name="MemoryDemo")
# Configure LLM
llm_config = LLMConfig(
model_name="gpt-4",
provider="openai",
api_key="your-api-key"
)
# Start the system
await pilott.start()
try:
# Add agents
researcher = await pilott.add_agent(
title="researcher",
goal="Gather information",
llm_config=llm_config
)
analyst = await pilott.add_agent(
title="analyst",
goal="Analyze information",
llm_config=llm_config
)
# Store information in researcher's memory
await researcher.memory.store_semantic(
text="US GDP grew by 2.5% in 2023",
metadata={"topic": "economics", "region": "US", "year": 2023},
tags={"economics", "gdp", "us"}
)
# Execute research job
research_result = await pilott.execute([{
"type": "research",
"description": "Research US economic growth",
"agent": "researcher"
}])
# Store analysis in analyst's memory
await analyst.memory.store_semantic(
text="Analysis shows strong correlation between GDP growth and employment rates",
metadata={"analysis_type": "correlation", "variables": ["gdp", "employment"]},
tags={"analysis", "economics", "correlation"}
)
# Execute analysis job using context from previous research
analysis_result = await pilott.execute([{
"type": "analyze",
"description": "Analyze impact of GDP growth on employment",
"context": {"research_result": research_result[0].output},
"agent": "analyst"
}])
# Retrieve similar analyses from memory
similar_analyses = await analyst.memory.search(
query="GDP employment correlation",
tags={"analysis"},
limit=3
)
print(f"Analysis result: {analysis_result[0].output}")
print(f"Similar analyses: {similar_analyses}")
finally:
# Always stop the system properly
await pilott.stop()
if __name__ == "__main__":
asyncio.run(memory_example())