General AI Agents are the core building blocks of the PandaAGI SDK.
They are autonomous AI entities that can understand natural language, make decisions, use tools, and interact with their environment to accomplish tasks.
PandaAGI general AI agents consist of four key components:
WebSocket Communication: Real-time bidirectional connection with the AGI backend server
Tool Handlers: Pluggable modules that provide different capabilities and tool access
Environment Integration: Isolated workspace for secure file and system operations
Event Streaming: Real-time transmission of agent thoughts, actions, and results
PandaAGI offers two powerful agentic models to suit your needs. You can specify the model using the model parameter in the Agent constructor.
Model
Description
annie-pro
Our most powerful and advanced generalist agentic technology. It excels at complex reasoning, multi-step task planning, and sophisticated skill integration. This is the recommended model for production applications that require high accuracy and robust performance.
annie-lite
A super powerful, yet lightweight, generalist agentic model optimized for speed and efficiency, at a fraction of the cost. It’s ideal for rapid prototyping, simple automation tasks, and applications where response time is critical.
By default, the SDK uses annie-pro. You can select annie-lite like this:
from panda_agi.envs import LocalEnv# Custom workspace directoryenv = LocalEnv("./agent_workspace")agent = Agent(environment=env)# Change working directoryagent.change_working_directory("/path/to/project")# Get current directorycurrent_dir = agent.get_working_directory()
Enable follow-up questions and maintain context across multiple requests:
import asyncioimport uuidfrom panda_agi import Agentfrom panda_agi.handlers import LogsHandlerasync def persistent_conversation(): # Use same conversation_id for related requests # Must be a proper UUID4 string conversation_id = str(uuid.uuid4()) handlers = [LogsHandler(use_colors=True, show_timestamps=True)] agent = Agent(conversation_id=conversation_id, event_handlers=handlers) # First request response1 = await agent.run("Tell me about Alice in Wonderland") print(f"First response: {response1.output}") # Follow-up request with context response2 = await agent.run("What's the main character's personality like?") print(f"Follow-up response: {response2.output}") # Should mention "Alice"if __name__ == "__main__": asyncio.run(persistent_conversation())
Key Benefits:
Context Retention: Agent remembers previous questions and answers
Natural Conversations: Ask follow-up questions without repeating context
Session Persistence: Maintain conversations across multiple script runs
Important: The conversation_id must be a valid UUID4 string generated with str(uuid.uuid4()). This ensures proper conversation tracking and prevents conflicts.
Maintain conversations across different script executions:
# session1.pyimport asyncioimport uuidfrom panda_agi import Agent, EventTypefrom panda_agi.handlers import LogsHandler# Generate and save conversation ID for reuseCONVERSATION_ID = str(uuid.uuid4())print(f"Conversation ID: {CONVERSATION_ID}")# Save this ID to reuse in session2.pyasync def start_research(): # Start a research session agent = Agent(conversation_id=CONVERSATION_ID) handlers = [LogsHandler(use_colors=True, show_timestamps=True)] response = await agent.run("Please analyze the Python project in my workspace") print(f"Analysis complete: {response.output}") print("Check session2.py for follow-ups.")if __name__ == "__main__": asyncio.run(start_research())
# session2.py - Run this later with the same conversation IDimport asynciofrom panda_agi import Agent, EventTypefrom panda_agi.handlers import LogsHandler# Use the same conversation ID from session1.pyCONVERSATION_ID = "your-uuid-from-session1" # Replace with actual UUIDasync def continue_research(): handlers = [LogsHandler(use_colors=True, show_timestamps=True)] # Continue the same conversation agent = Agent(conversation_id=CONVERSATION_ID, event_handlers=handlers) # Agent remembers the previous analysis response = await agent.run("Based on your analysis, what improvements would you suggest?") print(f"Improvement suggestions completed: {response.output}")if __name__ == "__main__": asyncio.run(continue_research())
# Use context managers when possibleasync with Agent() as agent: # Work with agent pass# Or ensure proper cleanupagent = Agent()try: # Work with agent passfinally: await agent.disconnect()