Files
python-sdk/examples/self_learning_agent.py
T
zooqueenandHanzo Dev 0834abe2aa style: auto-fix ruff lint and format for Python 3.12
Run ruff check --fix and ruff format across the repo to fix ~495
auto-fixable lint errors (mostly I001 import sorting) and reformat
225 files to match the py312 target.

Co-authored-by: Hanzo Dev <[email protected]>
2026-02-20 21:29:31 -08:00

39 lines
1.3 KiB
Python

from agents import Agent, Runner, ReflexionEngine
from agents.reflexion import Rule
from hanzo_memory.client import SQLiteMemoryClient
async def main():
# 1. Initialize Memory Client (SQLite)
# Ensure the DB exists or is created
db_client = SQLiteMemoryClient(user_id="test_user")
# 2. Initialize Reflexion Engine
reflexion = ReflexionEngine(memory_client=db_client)
# 3. Add some initial rules (simulating past learning)
await reflexion.add_rule("Always double check file paths before writing.", context="coding")
# 4. Create an Agent with Reflexion
agent = Agent(
name="SelfLearningBot",
instructions="You are a helpful assistant that learns from mistakes.",
reflexion=reflexion,
)
# 5. Simulate a run (in a real scenario, the runner would use these)
print(f"Agent {agent.name} initialized.")
rules = await agent.reflexion.load_rules(context="coding")
print(f"Loaded {len(rules)} rules for context 'coding':")
for r in rules:
print(f" - {r.content}")
# 6. Simulate a learning event
print("\nSimulating reflection...")
new_rule = await agent.reflexion.add_rule("Use pathlib for path manipulations.", context="coding")
print(f"Added new rule: {new_rule.content}")
if __name__ == "__main__":
asyncio.run(main())