supermemory/packages/agent-framework-python/test_real.py
Dhravya Shah 2c46964dfa
Migrate Agent Framework integration to Supermemory v5 (#1786)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-10-09 14:52:36 -07:00

59 lines
1.4 KiB
Python

import asyncio
import os
from agent_framework.openai import OpenAIChatClient
from supermemory_agent_framework import (
AgentSupermemory,
SupermemoryChatMiddleware,
SupermemoryMiddlewareOptions,
SupermemoryTools,
)
async def main():
conn = AgentSupermemory(
api_key=os.environ["SUPERMEMORY_API_KEY"],
container_tag="test-user-123",
)
middleware = SupermemoryChatMiddleware(
conn,
options=SupermemoryMiddlewareOptions(
mode="full",
verbose=True,
add_memory="always",
),
)
tools = SupermemoryTools(conn)
agent = OpenAIChatClient(
api_key=os.environ["OPENAI_API_KEY"], model="gpt-5"
).as_agent(
name="MemoryAgent",
instructions="You are a helpful assistant with memory.",
middleware=[middleware],
tools=tools.get_tools(),
)
print("Chat with the agent (type 'quit' to exit)")
print("-" * 40)
while True:
try:
user_input = input("\nYou: ")
except (EOFError, KeyboardInterrupt):
print("\nBye!")
break
if user_input.strip().lower() in ("quit", "exit"):
print("Bye!")
break
response = await agent.run(user_input)
await middleware.wait_for_background_tasks()
print(f"\nAgent: {response.text}")
asyncio.run(main())