CodeAgent or ToolCallingAgent persistent memory through Synap. Smolagents keeps its own fixed step log with no pluggable memory backend, so Synap plugs into the extension points it does expose: @tool functions, a step_callbacks recorder, and static instructions.
Requires Python 3.11+ and
smolagents>=1.26.Overview
Three surfaces, mapped onto Smolagents’ own extension points. Adopt only the ones you need.
All three take an already-constructed
MaximemSynapSDK — your app owns the SDK and its credentials.
Setup
Basic integration
Give the agent memory tools it can call. BecauseCodeAgent writes its actions as Python, search_memory / store_memory compose naturally into the code it generates.
Core concepts
create_synap_tools
Returnssearch_memory and store_memory as Smolagents @tool functions. search_memory reads Synap’s long-term layer and returns formatted context; store_memory ingests a fact for future recall. Reads degrade to a not-found message; the write raises SynapIntegrationError so a failed store is observable.
create_synap_recorder
Records each completed step into Synap. Register it per step type on the agent:ActionStep is written to its own Synap document, so a multi-step run is captured in full. Failed or empty steps are skipped.
synap_st_instructions
Smolagents’instructions is a static string, so short-term context is folded into it once at construction.
conversation_id is required. Empty context is a no-op; SDK failures are swallowed by default (on_error="fallback"), or set on_error="raise" for strict environments.
Complete example: memory-augmented CodeAgent
Advanced patterns
Synchronous framework, async SDK
Smolagents runs synchronously and its tools do not supportasync, so every surface bridges to the async Synap SDK internally (via the shared run_async helper). If your application is otherwise async, follow Hugging Face’s guidance and run the agent on its own thread (e.g. await anyio.to_thread.run_sync(agent.run, task)).
Error policy
- The
search_memorytool degrades — a Synap blip returns a not-found message. - The
store_memorytool raisesSynapIntegrationErroron failure (model-driven, user-initiated). - The recorder logs and never raises. It runs inside the agent loop, in a
finallywith no surrounding try/except, so a raising callback would abort the whole run — a failed ingest is logged and swallowed.
Going further
- Scoping.
user_idandcustomer_idflow straight to Synap; per-user isolation and B2C/B2B scope are derived server-side from the ids you pass.
Next steps
SDK: Ingestion
How
memories.create extraction differs from conversation recording.Integrations overview
Every framework Synap plugs into.