CAMEL-AI integration
Astrocyte as role-based memory for CAMEL-AI multi-agent role-playing systems.
Module: astrocyte.integrations.camel_ai
Pattern: Role-scoped memory — write/read with role attribution and per-role banks
Framework dependency: camel-ai (optional)
Install
Section titled “Install”pip install astrocyte camel-aifrom astrocyte import Astrocytefrom astrocyte.integrations.camel_ai import AstrocyteCamelMemory
brain = Astrocyte.from_config("astrocyte.yaml")
# Role-based memory for multi-agent role-playingmemory = AstrocyteCamelMemory( brain, bank_id="simulation", role_banks={"doctor": "doctor-bank", "patient": "patient-bank"},)
# Write with role attributionawait memory.write("Patient reports headaches", role="doctor", agent_id="agent-1")await memory.write("I've had headaches for a week", role="patient")
# Read scoped by roleresults = await memory.read("symptoms", role="doctor")context = await memory.get_context("patient history", role="doctor")
# Synthesize across role's memoryanswer = await memory.reflect("What symptoms have been reported?", role="doctor")
# Clear a role's memoryawait memory.clear(role="patient")Integration pattern
Section titled “Integration pattern”Memories are tagged with role:{role_name} and camel-ai for filtering. Each role can have its own bank or share a common bank.
| Method | Astrocyte call |
|---|---|
write(content, role=...) | brain.retain() with role metadata + tags |
read(query, role=...) | brain.recall() scoped to role’s bank |
get_context(query, role=...) | brain.recall() → formatted string |
reflect(query, role=...) | brain.reflect() on role’s bank |
clear(role=...) | brain.clear_bank() on role’s bank |
End-to-end example
Section titled “End-to-end example”A medical simulation where doctor and patient roles have separate memories:
import asynciofrom astrocyte import Astrocytefrom astrocyte.integrations.camel_ai import AstrocyteCamelMemory
brain = Astrocyte.from_config("astrocyte.yaml")
memory = AstrocyteCamelMemory( brain, bank_id="medical-sim", role_banks={"doctor": "doctor-notes", "patient": "patient-history"},)
async def main(): # Patient describes symptoms (stored in patient bank) await memory.write( "I've had recurring headaches for 2 weeks, mostly in the morning", role="patient", ) await memory.write( "The pain is usually a 6/10, located behind the eyes", role="patient", )
# Doctor records observations (stored in doctor bank) await memory.write( "Patient presents with tension-type headache pattern", role="doctor", agent_id="dr-smith", )
# Doctor reviews patient history history = await memory.read("headache symptoms", role="patient") for hit in history: print(f" Patient said: {hit['text']}")
# Doctor synthesizes diagnosis assessment = await memory.reflect( "Based on patient symptoms, what is the likely diagnosis?", role="doctor", ) print(f"Assessment: {assessment}")
# Get formatted context for prompt injection ctx = await memory.get_context("patient symptoms", role="patient") print(ctx)
asyncio.run(main())API reference
Section titled “API reference”AstrocyteCamelMemory(brain, bank_id, *, role_banks=None)
Section titled “AstrocyteCamelMemory(brain, bank_id, *, role_banks=None)”| Parameter | Type | Description |
|---|---|---|
brain | Astrocyte | Configured Astrocyte instance |
bank_id | str | Shared simulation bank |
role_banks | dict[str, str] | Role name → bank ID for per-role isolation |