AutoGen / AG2 integration
Astrocyte memory for Microsoft AutoGen multi-agent conversations, with both direct API and tool registration.
Module: astrocyte.integrations.autogen
Pattern: Memory API (save/query/get_context) + OpenAI-format tool export
Framework dependency: ag2 (optional)
Install
Section titled “Install”pip install astrocyte ag2Usage — Direct memory API
Section titled “Usage — Direct memory API”from astrocyte import Astrocytefrom astrocyte.integrations.autogen import AstrocyteAutoGenMemory
brain = Astrocyte.from_config("astrocyte.yaml")memory = AstrocyteAutoGenMemory( brain, bank_id="team", agent_banks={"agent-a": "bank-a", "agent-b": "bank-b"},)
# Save in conversation hooksawait memory.save("User prefers Python", agent_id="agent-a")
# Get formatted context for injectioncontext = await memory.get_context("What does the user prefer?")# → "- User prefers Python"Usage — Tool registration
Section titled “Usage — Tool registration”# Export as OpenAI-format tools for function callingtools = memory.as_tools()handlers = memory.get_handlers()
# Register with ConversableAgentagent = ConversableAgent("assistant", llm_config=llm_config)Integration pattern
Section titled “Integration pattern”| Method | Astrocyte call |
|---|---|
save(content, agent_id=...) | brain.retain() with agent metadata |
query(query, agent_id=...) | brain.recall() → list of hit dicts |
get_context(query) | brain.recall() → formatted string |
as_tools() | OpenAI-format tool definitions |
get_handlers() | Async handler functions for tool dispatch |
API reference
Section titled “API reference”AstrocyteAutoGenMemory(brain, bank_id, *, agent_banks=None)
Section titled “AstrocyteAutoGenMemory(brain, bank_id, *, agent_banks=None)”| Parameter | Type | Description |
|---|---|---|
brain | Astrocyte | Configured Astrocyte instance |
bank_id | str | Shared team bank |
agent_banks | dict[str, str] | Agent ID → bank ID for per-agent memory |