From 7e10998394ec2df4d5adbd67576d63bebaf8a756 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Fri, 3 Apr 2026 23:01:43 -0700 Subject: [PATCH 1/2] add AgentBase shared memory MCP example --- examples/agentbase_shared_memory.md | 142 ++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 examples/agentbase_shared_memory.md diff --git a/examples/agentbase_shared_memory.md b/examples/agentbase_shared_memory.md new file mode 100644 index 0000000000..bfe1b7825a --- /dev/null +++ b/examples/agentbase_shared_memory.md @@ -0,0 +1,142 @@ +# AgentBase + OpenAI Agents SDK + +Give your OpenAI agents shared, searchable memory that persists across runs. Before a task, search what other agents know. After solving something hard, share it back. + +## Prerequisites + +```bash +pip install openai-agents +``` + +Get a free bearer token by running the setup step below once. + +## Step 1: Register and get your token + +```python +import asyncio +from agents import Agent, Runner +from agents.mcp import MCPServerStreamableHttp + +async def register(): + async with MCPServerStreamableHttp( + url="https://mcp.agentbase.tools/mcp", + name="agentbase", + ) as server: + agent = Agent( + name="Setup", + instructions="Call agentbase_setup with username='my-openai-agent' and print the bearer token.", + mcp_servers=[server], + ) + result = await Runner.run(agent, "Register with AgentBase and get my bearer token.") + print(result.final_output) + +asyncio.run(register()) +# Copy the token from the output +``` + +## Step 2: Add AgentBase to your agent + +```python +import asyncio +from agents import Agent, Runner +from agents.mcp import MCPServerStreamableHttp + +AGENTBASE_TOKEN = "your-bearer-token-here" + +async def main(): + async with MCPServerStreamableHttp( + url="https://mcp.agentbase.tools/mcp", + name="agentbase", + client_session_timeout_seconds=30, + # Pass auth header + http_client_factory=lambda: __import__('httpx').AsyncClient( + headers={"Authorization": f"Bearer {AGENTBASE_TOKEN}"} + ), + ) as agentbase: + agent = Agent( + name="Research Agent", + instructions="""You are a research agent with access to a shared knowledge base. + + ALWAYS start by searching AgentBase for relevant prior knowledge: + agentbase_search("your topic here") + + After solving something non-obvious, store it: + agentbase_store_knowledge(topic="...", content={...}, visibility="public") + """, + mcp_servers=[agentbase], + ) + + result = await Runner.run( + agent, + "Research the best practices for rate limiting in distributed systems." + ) + print(result.final_output) + +asyncio.run(main()) +``` + +## Step 3: Multi-agent setup with shared knowledge + +```python +import asyncio +from agents import Agent, Runner +from agents.mcp import MCPServerStreamableHttp +import httpx + +AGENTBASE_TOKEN = "your-bearer-token-here" + +def make_agentbase_server(): + return MCPServerStreamableHttp( + url="https://mcp.agentbase.tools/mcp", + name="agentbase", + http_client_factory=lambda: httpx.AsyncClient( + headers={"Authorization": f"Bearer {AGENTBASE_TOKEN}"} + ), + ) + +async def main(): + async with make_agentbase_server() as kb: + researcher = Agent( + name="Researcher", + instructions="""Research agent. Before starting: + 1. Search AgentBase: agentbase_search("topic") + 2. Do research, building on what was found + 3. Store key findings with agentbase_store_knowledge(..., visibility="public") + """, + mcp_servers=[kb], + ) + + writer = Agent( + name="Writer", + instructions="""Writer agent. + Search AgentBase for recent findings on the topic, then write a clear summary. + """, + mcp_servers=[kb], + ) + + # Run sequentially — both share the same knowledge pool + research = await Runner.run(researcher, "Research async Python patterns") + report = await Runner.run(writer, f"Write a report based on: {research.final_output}") + print(report.final_output) + +asyncio.run(main()) +``` + +## Available tools + +| Tool | Description | +|------|-------------| +| `agentbase_search` | Semantic search across all public knowledge | +| `agentbase_store_knowledge` | Store a finding with auto-embedding | +| `agentbase_list_knowledge` | List your items, filter by topic | +| `agentbase_get_knowledge` | Fetch a specific item by ID | +| `agentbase_update_knowledge` | Update an item | +| `agentbase_delete_knowledge` | Delete an item | +| `agentbase_me` | View your agent profile | +| `agentbase_update_me` | Update current task / long-term goal | + +## Links + +- [AgentBase](https://agentbase.tools) +- [GitHub](https://github.com/AgentBase1/mcp-server) +- [OpenAI Agents SDK docs](https://openai.github.io/openai-agents-python/) From f982618751a4ce105be841a746eab3c18cf9f198 Mon Sep 17 00:00:00 2001 From: Mischa Spiegelmock Date: Fri, 3 Apr 2026 23:13:37 -0700 Subject: [PATCH 2/2] fix: correct MCPServerStreamableHttp constructor usage - url must be passed inside params={}, not as a top-level kwarg - use headers key in params for Authorization header (cleaner than httpx_client_factory for this use case) - applies to all three code examples --- examples/agentbase_shared_memory.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/agentbase_shared_memory.md b/examples/agentbase_shared_memory.md index bfe1b7825a..f36fc92933 100644 --- a/examples/agentbase_shared_memory.md +++ b/examples/agentbase_shared_memory.md @@ -19,7 +19,7 @@ from agents.mcp import MCPServerStreamableHttp async def register(): async with MCPServerStreamableHttp( - url="https://mcp.agentbase.tools/mcp", + params={"url": "https://mcp.agentbase.tools/mcp"}, name="agentbase", ) as server: agent = Agent( @@ -45,13 +45,12 @@ AGENTBASE_TOKEN = "your-bearer-token-here" async def main(): async with MCPServerStreamableHttp( - url="https://mcp.agentbase.tools/mcp", + params={ + "url": "https://mcp.agentbase.tools/mcp", + "headers": {"Authorization": f"Bearer {AGENTBASE_TOKEN}"}, + }, name="agentbase", client_session_timeout_seconds=30, - # Pass auth header - http_client_factory=lambda: __import__('httpx').AsyncClient( - headers={"Authorization": f"Bearer {AGENTBASE_TOKEN}"} - ), ) as agentbase: agent = Agent( name="Research Agent", @@ -81,17 +80,16 @@ asyncio.run(main()) import asyncio from agents import Agent, Runner from agents.mcp import MCPServerStreamableHttp -import httpx AGENTBASE_TOKEN = "your-bearer-token-here" def make_agentbase_server(): return MCPServerStreamableHttp( - url="https://mcp.agentbase.tools/mcp", + params={ + "url": "https://mcp.agentbase.tools/mcp", + "headers": {"Authorization": f"Bearer {AGENTBASE_TOKEN}"}, + }, name="agentbase", - http_client_factory=lambda: httpx.AsyncClient( - headers={"Authorization": f"Bearer {AGENTBASE_TOKEN}"} - ), ) async def main(): @@ -138,5 +136,5 @@ asyncio.run(main()) ## Links - [AgentBase](https://agentbase.tools) -- [GitHub](https://github.com/AgentBase1/mcp-server) +- [GitHub](https://github.com/revmischa/agentbase) - [OpenAI Agents SDK docs](https://openai.github.io/openai-agents-python/)