- Implemented ReAct loop in agent.py - Added Anthropic provider using httpx (no SDK) - Created tools: read, write, edit, bash - Added session management with JSONL format - Included configuration system with env var support - Added CLI interface and example usage - Minimal dependencies: only httpx
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Example usage of PicoGent
|
|
"""
|
|
|
|
import asyncio
|
|
from picogent import Agent, Config
|
|
|
|
|
|
async def main():
|
|
"""Example usage"""
|
|
|
|
# Load config
|
|
config = Config.from_file("config.example.json")
|
|
|
|
# Create agent
|
|
agent = Agent(config)
|
|
|
|
# Simple chat example
|
|
print("=== Simple Chat ===")
|
|
response = await agent.chat("List all files in the current directory")
|
|
print(response)
|
|
print()
|
|
|
|
# Session-based conversation
|
|
print("=== Session-based Conversation ===")
|
|
agent.clear_session() # Start fresh
|
|
|
|
response1 = await agent.run("Create a simple hello.py file", session_file="example_session.jsonl")
|
|
print("Step 1:", response1)
|
|
print()
|
|
|
|
response2 = await agent.run("Now read the file you just created", session_file="example_session.jsonl")
|
|
print("Step 2:", response2)
|
|
print()
|
|
|
|
# Show session history
|
|
print("=== Session History ===")
|
|
messages = agent.get_session_messages()
|
|
for i, msg in enumerate(messages):
|
|
print(f"{i+1}. {msg['role']}: {str(msg['content'])[:100]}...")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |