ampup-memory 0.3.1__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,331 @@
1
+ Metadata-Version: 2.5
2
+ Name: ampup-memory
3
+ Version: 0.3.3
4
+ Summary: A thin Python client for an AmpUp Memory server: team memory for coding agents
5
+ Project-URL: Homepage, https://github.com/A79-ai/ampup-memory
6
+ Project-URL: Source, https://github.com/A79-ai/ampup-memory/tree/main/sdk/python
7
+ Project-URL: Issues, https://github.com/A79-ai/ampup-memory/issues
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Keywords: agents,ampup,llm,mcp,memory
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: httpx>=0.27
18
+ Provides-Extra: claude-agent-sdk
19
+ Requires-Dist: claude-agent-sdk>=0.2; extra == 'claude-agent-sdk'
20
+ Provides-Extra: crewai
21
+ Requires-Dist: crewai>=1.15; extra == 'crewai'
22
+ Provides-Extra: google-adk
23
+ Requires-Dist: google-adk>=2.15; extra == 'google-adk'
24
+ Provides-Extra: langgraph
25
+ Requires-Dist: langchain>=1.0; extra == 'langgraph'
26
+ Requires-Dist: langgraph>=1.0; extra == 'langgraph'
27
+ Provides-Extra: litellm
28
+ Requires-Dist: litellm[proxy]>=1.111; extra == 'litellm'
29
+ Provides-Extra: openai-agents
30
+ Requires-Dist: openai-agents>=0.26; extra == 'openai-agents'
31
+ Provides-Extra: pydantic-ai
32
+ Requires-Dist: pydantic-ai-slim>=2.77; extra == 'pydantic-ai'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # ampup-memory
36
+
37
+ A thin Python client for an [AmpUp Memory](https://github.com/A79-ai/ampup-memory) server: write what your team
38
+ knows, search it, and get advice that improves as sessions are rewarded. One class, no codegen, and its only
39
+ dependency is `httpx`.
40
+
41
+ ```sh
42
+ pip install ampup-memory
43
+ ```
44
+
45
+ ## Quickstart
46
+
47
+ ```python
48
+ from datetime import datetime, timezone
49
+ from ampup_memory import AmpUpMemory, micros
50
+
51
+ mem = AmpUpMemory.from_profile() # the CLI's current context; or AmpUpMemory.from_profile("work")
52
+ # mem = AmpUpMemory("https://memory.example.com", "msk_...", org="acme") # an API key: yours (apikey create --personal) or a service's
53
+ # mem = AmpUpMemory("http://127.0.0.1:8080", None) # a local `ampup-memory serve --local`
54
+
55
+ ep = mem.remember("note:acme", "The Acme renewal is owned by Priya.")
56
+ print(mem.episode(ep["episode_id"]))
57
+ print(mem.search("who owns the Acme renewal", k=5))
58
+ print(mem.query({"find": "passages", "text": "Acme renewal"})["results"])
59
+ mem.ingest([{"source": "email:1", "body": "...", "occurred_at": micros(datetime.now(timezone.utc)), "acl": ["group:sales"]}])
60
+ ```
61
+
62
+ ## The learning loop
63
+
64
+ A session per task: advice as it goes, and how it went at the end. Advice is learned from sessions that ended with
65
+ a reward, and served to the next session of that kind of task.
66
+
67
+ ```python
68
+ run = mem.session("Handle a refund request for order 8841", harness="support-bot")
69
+ print(run.opening["advice"]) # what the memory has learned for this kind of task, or None
70
+ print(run.advice("Issue the $620 refund", moment="next")["advice"]) # moments: next, fork, stuck, done
71
+ run.end("refund issued after sign-off", reward=1) # -1 (failed) to 1 (succeeded)
72
+
73
+ mem.reward(run.id, -1, "the customer disputed it") # or reward it later, once you know
74
+ ```
75
+
76
+ Advice needs a server with a routing model: a hosted one, or `serve --local` with a model key (outside a session,
77
+ `advice()` raises a 503 without one). A `harness` ending in `:sdk` marks a session a program's: advice isn't learned
78
+ from it.
79
+
80
+ `from_profile()` uses the context and sign-in that `ampup-memory-client join <server> --org <org>` saved, in
81
+ `AMPUP_MEMORY_CONFIG_DIR` (default `~/.ampup-memory`). It picks the context from its argument, then
82
+ `AMPUP_MEMORY_CONTEXT`, then the current one, and renews an expiring sign-in with the saved refresh token, writing
83
+ it back where the CLI reads it.
84
+
85
+ ## Agent frameworks
86
+
87
+ An adapter makes each conversation of an agent built on a framework (Claude Agent SDK, OpenAI Agents SDK, LangGraph,
88
+ Google ADK, CrewAI, Pydantic AI, or any app behind the LiteLLM proxy) a memory session, as the AmpUp Memory plugin's
89
+ hooks do for a coding agent: the session starts with the user's first message, what the user and their team asked to
90
+ be remembered and advice for the message reach the model before it answers (every message asks for advice), the
91
+ model gets `search_memory` and `remember_memory` as tools (kept as the server's own `remember_memory` keeps a note:
92
+ the user's own until at least three people have said the same, where the server knows who is asking), and the
93
+ session ends with a transcript of at most 300 words. Make one adapter object per conversation (Google ADK's and
94
+ LiteLLM's serve many, one session each). A memory that is down never stops the agent: the turn goes on without it,
95
+ with a warning logged.
96
+
97
+ Each adapter finds the memory with `AmpUpMemory.connect()`, or takes a client as its first argument:
98
+
99
+ 1. `AMPUP_MEMORY_URL`, with `AMPUP_MEMORY_TOKEN` (sent only with it), `AMPUP_MEMORY_ORG` and `AMPUP_MEMORY_TEAM`;
100
+ 2. else, in personal mode (`personal.json` in `~/.ampup-memory`, or `AMPUP_MEMORY_PERSONAL=1`; `=0` turns it off),
101
+ the server on this machine: `http://127.0.0.1:${AMPUP_MEMORY_LOCAL_PORT}`, else personal.json's `port`, else 8080,
102
+ with `AMPUP_MEMORY_TOKEN` as its key where it is set (an engine's keyed port, `serve --local --keyed-port`, takes
103
+ only a key the local server made: point `AMPUP_MEMORY_LOCAL_PORT` at it);
104
+ 3. else the CLI's current context, as `from_profile()`.
105
+
106
+ ### Claude Agent SDK
107
+
108
+ ```sh
109
+ pip install "ampup-memory[claude-agent-sdk]"
110
+ ```
111
+
112
+ ```python
113
+ from claude_agent_sdk import query
114
+ from ampup_memory.integrations.claude_agent_sdk import ClaudeAgentMemory
115
+
116
+ memory = ClaudeAgentMemory()
117
+ async with memory: # ends the session on the way out, or call await memory.end(outcome, reward)
118
+ async for message in query(prompt="...", options=memory.options(model="haiku")):
119
+ ...
120
+ ```
121
+
122
+ `options(**kwargs)` is `ClaudeAgentOptions(**kwargs)` with the adapter's `hooks` (`UserPromptSubmit` hands the model
123
+ what memory has, `Stop` keeps the answer for the transcript), its in-process MCP server and `allowed_tools` added
124
+ to any you pass.
125
+
126
+ ### OpenAI Agents SDK
127
+
128
+ ```sh
129
+ pip install "ampup-memory[openai-agents]"
130
+ ```
131
+
132
+ ```python
133
+ from agents import Agent, Runner
134
+ from ampup_memory.integrations.openai_agents import OpenAIAgentsMemory
135
+
136
+ memory = OpenAIAgentsMemory()
137
+ agent = Agent(name="Assistant", instructions="...", tools=[*memory.tools])
138
+ async with memory:
139
+ result = await Runner.run(agent, "...", hooks=memory.hooks, run_config=memory.run_config())
140
+ ```
141
+
142
+ `run_config(base=None)` adds a `call_model_input_filter` that appends the guide and what memory has to the model
143
+ call's instructions; `hooks` keep the agent's final output for the transcript.
144
+
145
+ ### LangGraph
146
+
147
+ ```sh
148
+ pip install "ampup-memory[langgraph]"
149
+ ```
150
+
151
+ ```python
152
+ from langchain.agents import create_agent
153
+ from ampup_memory.integrations.langgraph import LangGraphMemory
154
+
155
+ memory = LangGraphMemory()
156
+ agent = create_agent(model, tools=[...], middleware=[memory]) # adds search_memory and remember_memory
157
+ with memory: # async with in async code
158
+ agent.invoke({"messages": [{"role": "user", "content": "..."}]})
159
+ ```
160
+
161
+ It is middleware for `create_agent`, LangGraph's prebuilt agent since 1.0: it adds to each model call's system
162
+ message and keeps the agent's last answer.
163
+
164
+ ### Google ADK
165
+
166
+ ```sh
167
+ pip install "ampup-memory[google-adk]"
168
+ ```
169
+
170
+ ```python
171
+ from google.adk.agents import Agent
172
+ from google.adk.runners import Runner
173
+ from ampup_memory.integrations.google_adk import GoogleADKMemory
174
+
175
+ memory = GoogleADKMemory() # one for the runner: each ADK session is its own memory session
176
+ agent = Agent(name="assistant", model="gemini-2.5-flash", instruction="...", tools=[*memory.tools])
177
+ runner = Runner(app_name="app", agent=agent, session_service=sessions,
178
+ memory_service=memory.service, plugins=[memory.plugin])
179
+ ... # run the conversation
180
+ await memory.service.add_session_to_memory(session) # ends its memory session with the transcript
181
+ ```
182
+
183
+ `service` is a `BaseMemoryService`: `search_memory` searches AmpUp Memory (ADK's own `load_memory` and
184
+ `preload_memory` tools read it), `add_session_to_memory` ends the ADK session's memory session with a transcript of
185
+ what was said since it last did (a later message opens a new one), and `add_memory` keeps notes. `plugin` adds the
186
+ guide and what memory has to each model call's system instruction and keeps the final answer. Without the plugin,
187
+ `add_session_to_memory` still records the session, opening it from the ADK session's first message.
188
+
189
+ ### CrewAI
190
+
191
+ ```sh
192
+ pip install "ampup-memory[crewai]"
193
+ ```
194
+
195
+ ```python
196
+ from crewai import Crew
197
+ from ampup_memory.integrations.crewai import CrewAIMemory
198
+
199
+ memory = CrewAIMemory()
200
+ crew = Crew(agents=[...], tasks=[...], memory=memory.memory)
201
+ with memory: # async with in async code
202
+ crew.kickoff(inputs={...})
203
+ ```
204
+
205
+ `memory.memory` is a CrewAI `Memory` (the unified memory of CrewAI 1.14 and later, which replaced its external
206
+ memory): its recall searches AmpUp Memory, so the crew's recall before each task and its own "Search memory" and
207
+ "Save to memory" tools reach it, and the raw task results CrewAI would turn into notes go into the transcript
208
+ instead. A model-call hook opens each task's turn and adds the guide and what memory has to the call's system
209
+ messages. An agent outside such a crew takes `memory.tools` (`search_memory` and `remember_memory`).
210
+
211
+ ### Pydantic AI
212
+
213
+ ```sh
214
+ pip install "ampup-memory[pydantic-ai]"
215
+ ```
216
+
217
+ ```python
218
+ from pydantic_ai import Agent
219
+ from ampup_memory.integrations.pydantic_ai import MemoryCapability, PydanticAIMemory
220
+
221
+ agent = Agent(model, deps_type=PydanticAIMemory, capabilities=[MemoryCapability()])
222
+ memory = PydanticAIMemory() # one per conversation, as the run's deps
223
+ async with memory:
224
+ result = await agent.run("...", deps=memory)
225
+ ```
226
+
227
+ The agent is made once; each conversation's memory travels in `deps` (a `PydanticAIMemory`, or your own deps with
228
+ one as `memory`). `MemoryCapability` is `memory_instructions` (a dynamic instruction: the guide and what memory has
229
+ for the run's prompt), `memory_toolset` and the run's output for the transcript; the first two also work alone, as
230
+ `Agent(instructions=memory_instructions, toolsets=[memory_toolset])`, with `memory.did(str(result.output))`.
231
+
232
+ ### LiteLLM proxy
233
+
234
+ ```sh
235
+ pip install "ampup-memory[litellm]"
236
+ ```
237
+
238
+ ```yaml
239
+ # config.yaml
240
+ litellm_settings:
241
+ callbacks: ampup_memory.integrations.litellm.callback
242
+ ```
243
+
244
+ ```sh
245
+ AMPUP_MEMORY_LITELLM_RECALL=1 litellm --config config.yaml
246
+ ```
247
+
248
+ An app that only points its OpenAI-compatible client at the proxy gets a memory session per conversation: each chat
249
+ completion that succeeds is a turn (advice is asked for each user message), and the session ends with its transcript
250
+ once the conversation has been idle for `AMPUP_MEMORY_LITELLM_IDLE_SECS` (600 by default) or the proxy stops. With
251
+ `AMPUP_MEMORY_LITELLM_RECALL=1`, what memory has for the user's message is added to the request's system message
252
+ before it goes to the model. A conversation is what the request names (`litellm_session_id`, or
253
+ `metadata.session_id`), else its key, `user` and first user message. The app has no memory tools, so what it gets back is what
254
+ other apps' agents remembered and, where the server keeps them, preferences from what users type.
255
+
256
+ ### Any other framework
257
+
258
+ `ampup_memory.integrations.Conversation` is what the adapters drive: `recall(prompt)` (the text to add to the
259
+ model's context for the turn the user's message opens), `did(text)` (the answer, for the transcript), `search` and
260
+ `remember` (the tools), and `end(outcome, reward)`; each with an `a`-prefixed async twin. `GUIDE` is the line that
261
+ tells the model when to use the tools (`guide(search, remember)` names them as your framework does). `Conversations`
262
+ holds many at once by a key, for a host that serves many conversations from one object.
263
+
264
+ ## Serving many tenants (platforms)
265
+
266
+ A platform (an app that serves many customers of its own) uses one platform key for all of them. Each request names
267
+ the tenant, by the platform's own id for that customer, and, optionally, the user acting in it. Memory creates a
268
+ tenant the first time a request names it and enrolls a user the same way; each tenant's memory, and what it learns,
269
+ stays inside it.
270
+
271
+ ```python
272
+ platform = AmpUpMemory("https://memory.example.com", "msk_...") # the platform key, on your server only
273
+
274
+ # Per request: a copy for that tenant and user. Copies share the connections; close only `platform`.
275
+ mem = platform.for_tenant("acme", name="Acme Corp").for_user("u_42", email="pat@example.com", name="Pat Lee")
276
+ run = mem.session("Draft the renewal email", harness="renewal-writer")
277
+ mem.ingest([{"source": "crm:note:9", "body": "...", "occurred_at": micros(datetime.now(timezone.utc)), "acl": ["user:u_42"]}])
278
+
279
+ platform.tenants.ensure("acme", name="Acme Corp") # {tenant, org, created}
280
+ platform.tenants.list(limit=100) # the platform's tenants and their usage
281
+ platform.tenants.forget_user("acme", "u_42") # a user leaves
282
+ platform.tenants.delete("acme") # purge the tenant; {purging: true} until it is done
283
+ ```
284
+
285
+ Or pass `tenant=`, `tenant_name=`, `user=`, `user_email=` and `user_name=` to the constructor. Tenant and user ids
286
+ are the platform's own: 1 to 128 printable ASCII characters, case-sensitive. Email and name are stored on the user
287
+ and kept up to date, never their identity. Names and emails can be any text: the client sends them percent-encoded
288
+ (UTF-8). A tenant's name only labels it when it is created. Without a user, a request is the tenant's own: it can
289
+ ingest and read what the whole tenant shares, but sessions, advice, `remember` and `forget` need a user. ACLs on
290
+ what the platform writes name its users as `user:<user id>` and the whole tenant as `group:all`.
291
+
292
+ Name each of your agents' sessions with its own `harness`, never one ending in `:sdk`: advice isn't learned from
293
+ those.
294
+
295
+ ## Methods
296
+
297
+ | Method | Route | Returns |
298
+ |---|---|---|
299
+ | `AmpUpMemory(server, token, *, org, team, tenant, tenant_name, user, user_email, user_name, timeout)` | | `token` may be `None` for a local server |
300
+ | `AmpUpMemory.from_profile(context=None)` | | a client for a CLI context |
301
+ | `AmpUpMemory.connect()` | | the memory this machine's agents use (see [Agent frameworks](#agent-frameworks)) |
302
+ | `for_tenant(tenant, *, name=None)` | | a copy for another tenant, as the tenant itself |
303
+ | `for_user(user, *, email=None, name=None)` | | a copy for another user of the same tenant |
304
+ | `me()` | `GET /me` | who you are: user, groups, scope, memberships |
305
+ | `ingest(episodes)` | `POST /ingest` | every episode id; sent in batches of 500; needs an ingest or admin key |
306
+ | `remember(source, body, *, acl, document)` | `POST /remember` | `{episode_id, scope, readers}`, or `{queued, message}` |
307
+ | `forget(episode_id)` | `POST /forget` | the forgotten id |
308
+ | `search(query, k=10)` | `POST /search` | a list of fact hits |
309
+ | `query(q)` | `POST /query` | a query-language result (`find`: entities, facts, count, changes, passages, schema, metrics) |
310
+ | `episode(episode_id)` | `POST /episode` | the episode's text, or `None` |
311
+ | `session(task, *, harness)` | `POST /sessions` | a `Session`: `id`, `task`, `opening` (the advice served at its start) |
312
+ | `Session.advice(question=None, *, moment, conversation)` | `POST /advice` | advice for the task or the step at hand, recorded in the session |
313
+ | `Session.end(outcome, reward, *, transcript, reason)` | `POST /sessions/end` | `{ended, served, session_id}` |
314
+ | `advice(question)` | `POST /advice` | advice outside any session |
315
+ | `call_tool(name, arguments)` | `POST /mcp` | one of the server's MCP tools (`start_session`, `get_advice`, `search_memory`, ...): its text |
316
+ | `reward(run_id, reward, reason=None)` | `POST /runs/reward` | the id; rewards an ended session (written within a minute of its end) or a run |
317
+ | `tenants.ensure(tenant, name=None)` | `PUT /tenants/{tenant}` | `{tenant, org, created}` |
318
+ | `tenants.get(tenant)` | `GET /tenants/{tenant}` | `{tenant, org, created_at, limits, usage}`; 404 if unknown |
319
+ | `tenants.list(after=None, limit=None)` | `GET /tenants` | a page of the platform's tenants with usage (up to 500) |
320
+ | `tenants.delete(tenant)` | `DELETE /tenants/{tenant}` | purges the tenant; `{purging: true}` while it runs |
321
+ | `tenants.forget_user(tenant, user)` | `POST /tenants/{tenant}/users/{user}/forget` | forgets the user and what they wrote |
322
+ | `micros(datetime)` | | `occurred_at` in microseconds since the epoch |
323
+
324
+ Every failure raises `AmpUpMemoryError` with `status`, `message` and, on a 429, `retry_after`. An error the
325
+ server reports inside a row (a bad query, say) raises it too, with status 200.
326
+
327
+ The TypeScript client with the same methods is [`ampup-memory`](https://github.com/A79-ai/ampup-memory/tree/main/sdk/typescript).
328
+
329
+ ## License
330
+
331
+ Apache-2.0.
@@ -0,0 +1,297 @@
1
+ # ampup-memory
2
+
3
+ A thin Python client for an [AmpUp Memory](https://github.com/A79-ai/ampup-memory) server: write what your team
4
+ knows, search it, and get advice that improves as sessions are rewarded. One class, no codegen, and its only
5
+ dependency is `httpx`.
6
+
7
+ ```sh
8
+ pip install ampup-memory
9
+ ```
10
+
11
+ ## Quickstart
12
+
13
+ ```python
14
+ from datetime import datetime, timezone
15
+ from ampup_memory import AmpUpMemory, micros
16
+
17
+ mem = AmpUpMemory.from_profile() # the CLI's current context; or AmpUpMemory.from_profile("work")
18
+ # mem = AmpUpMemory("https://memory.example.com", "msk_...", org="acme") # an API key: yours (apikey create --personal) or a service's
19
+ # mem = AmpUpMemory("http://127.0.0.1:8080", None) # a local `ampup-memory serve --local`
20
+
21
+ ep = mem.remember("note:acme", "The Acme renewal is owned by Priya.")
22
+ print(mem.episode(ep["episode_id"]))
23
+ print(mem.search("who owns the Acme renewal", k=5))
24
+ print(mem.query({"find": "passages", "text": "Acme renewal"})["results"])
25
+ mem.ingest([{"source": "email:1", "body": "...", "occurred_at": micros(datetime.now(timezone.utc)), "acl": ["group:sales"]}])
26
+ ```
27
+
28
+ ## The learning loop
29
+
30
+ A session per task: advice as it goes, and how it went at the end. Advice is learned from sessions that ended with
31
+ a reward, and served to the next session of that kind of task.
32
+
33
+ ```python
34
+ run = mem.session("Handle a refund request for order 8841", harness="support-bot")
35
+ print(run.opening["advice"]) # what the memory has learned for this kind of task, or None
36
+ print(run.advice("Issue the $620 refund", moment="next")["advice"]) # moments: next, fork, stuck, done
37
+ run.end("refund issued after sign-off", reward=1) # -1 (failed) to 1 (succeeded)
38
+
39
+ mem.reward(run.id, -1, "the customer disputed it") # or reward it later, once you know
40
+ ```
41
+
42
+ Advice needs a server with a routing model: a hosted one, or `serve --local` with a model key (outside a session,
43
+ `advice()` raises a 503 without one). A `harness` ending in `:sdk` marks a session a program's: advice isn't learned
44
+ from it.
45
+
46
+ `from_profile()` uses the context and sign-in that `ampup-memory-client join <server> --org <org>` saved, in
47
+ `AMPUP_MEMORY_CONFIG_DIR` (default `~/.ampup-memory`). It picks the context from its argument, then
48
+ `AMPUP_MEMORY_CONTEXT`, then the current one, and renews an expiring sign-in with the saved refresh token, writing
49
+ it back where the CLI reads it.
50
+
51
+ ## Agent frameworks
52
+
53
+ An adapter makes each conversation of an agent built on a framework (Claude Agent SDK, OpenAI Agents SDK, LangGraph,
54
+ Google ADK, CrewAI, Pydantic AI, or any app behind the LiteLLM proxy) a memory session, as the AmpUp Memory plugin's
55
+ hooks do for a coding agent: the session starts with the user's first message, what the user and their team asked to
56
+ be remembered and advice for the message reach the model before it answers (every message asks for advice), the
57
+ model gets `search_memory` and `remember_memory` as tools (kept as the server's own `remember_memory` keeps a note:
58
+ the user's own until at least three people have said the same, where the server knows who is asking), and the
59
+ session ends with a transcript of at most 300 words. Make one adapter object per conversation (Google ADK's and
60
+ LiteLLM's serve many, one session each). A memory that is down never stops the agent: the turn goes on without it,
61
+ with a warning logged.
62
+
63
+ Each adapter finds the memory with `AmpUpMemory.connect()`, or takes a client as its first argument:
64
+
65
+ 1. `AMPUP_MEMORY_URL`, with `AMPUP_MEMORY_TOKEN` (sent only with it), `AMPUP_MEMORY_ORG` and `AMPUP_MEMORY_TEAM`;
66
+ 2. else, in personal mode (`personal.json` in `~/.ampup-memory`, or `AMPUP_MEMORY_PERSONAL=1`; `=0` turns it off),
67
+ the server on this machine: `http://127.0.0.1:${AMPUP_MEMORY_LOCAL_PORT}`, else personal.json's `port`, else 8080,
68
+ with `AMPUP_MEMORY_TOKEN` as its key where it is set (an engine's keyed port, `serve --local --keyed-port`, takes
69
+ only a key the local server made: point `AMPUP_MEMORY_LOCAL_PORT` at it);
70
+ 3. else the CLI's current context, as `from_profile()`.
71
+
72
+ ### Claude Agent SDK
73
+
74
+ ```sh
75
+ pip install "ampup-memory[claude-agent-sdk]"
76
+ ```
77
+
78
+ ```python
79
+ from claude_agent_sdk import query
80
+ from ampup_memory.integrations.claude_agent_sdk import ClaudeAgentMemory
81
+
82
+ memory = ClaudeAgentMemory()
83
+ async with memory: # ends the session on the way out, or call await memory.end(outcome, reward)
84
+ async for message in query(prompt="...", options=memory.options(model="haiku")):
85
+ ...
86
+ ```
87
+
88
+ `options(**kwargs)` is `ClaudeAgentOptions(**kwargs)` with the adapter's `hooks` (`UserPromptSubmit` hands the model
89
+ what memory has, `Stop` keeps the answer for the transcript), its in-process MCP server and `allowed_tools` added
90
+ to any you pass.
91
+
92
+ ### OpenAI Agents SDK
93
+
94
+ ```sh
95
+ pip install "ampup-memory[openai-agents]"
96
+ ```
97
+
98
+ ```python
99
+ from agents import Agent, Runner
100
+ from ampup_memory.integrations.openai_agents import OpenAIAgentsMemory
101
+
102
+ memory = OpenAIAgentsMemory()
103
+ agent = Agent(name="Assistant", instructions="...", tools=[*memory.tools])
104
+ async with memory:
105
+ result = await Runner.run(agent, "...", hooks=memory.hooks, run_config=memory.run_config())
106
+ ```
107
+
108
+ `run_config(base=None)` adds a `call_model_input_filter` that appends the guide and what memory has to the model
109
+ call's instructions; `hooks` keep the agent's final output for the transcript.
110
+
111
+ ### LangGraph
112
+
113
+ ```sh
114
+ pip install "ampup-memory[langgraph]"
115
+ ```
116
+
117
+ ```python
118
+ from langchain.agents import create_agent
119
+ from ampup_memory.integrations.langgraph import LangGraphMemory
120
+
121
+ memory = LangGraphMemory()
122
+ agent = create_agent(model, tools=[...], middleware=[memory]) # adds search_memory and remember_memory
123
+ with memory: # async with in async code
124
+ agent.invoke({"messages": [{"role": "user", "content": "..."}]})
125
+ ```
126
+
127
+ It is middleware for `create_agent`, LangGraph's prebuilt agent since 1.0: it adds to each model call's system
128
+ message and keeps the agent's last answer.
129
+
130
+ ### Google ADK
131
+
132
+ ```sh
133
+ pip install "ampup-memory[google-adk]"
134
+ ```
135
+
136
+ ```python
137
+ from google.adk.agents import Agent
138
+ from google.adk.runners import Runner
139
+ from ampup_memory.integrations.google_adk import GoogleADKMemory
140
+
141
+ memory = GoogleADKMemory() # one for the runner: each ADK session is its own memory session
142
+ agent = Agent(name="assistant", model="gemini-2.5-flash", instruction="...", tools=[*memory.tools])
143
+ runner = Runner(app_name="app", agent=agent, session_service=sessions,
144
+ memory_service=memory.service, plugins=[memory.plugin])
145
+ ... # run the conversation
146
+ await memory.service.add_session_to_memory(session) # ends its memory session with the transcript
147
+ ```
148
+
149
+ `service` is a `BaseMemoryService`: `search_memory` searches AmpUp Memory (ADK's own `load_memory` and
150
+ `preload_memory` tools read it), `add_session_to_memory` ends the ADK session's memory session with a transcript of
151
+ what was said since it last did (a later message opens a new one), and `add_memory` keeps notes. `plugin` adds the
152
+ guide and what memory has to each model call's system instruction and keeps the final answer. Without the plugin,
153
+ `add_session_to_memory` still records the session, opening it from the ADK session's first message.
154
+
155
+ ### CrewAI
156
+
157
+ ```sh
158
+ pip install "ampup-memory[crewai]"
159
+ ```
160
+
161
+ ```python
162
+ from crewai import Crew
163
+ from ampup_memory.integrations.crewai import CrewAIMemory
164
+
165
+ memory = CrewAIMemory()
166
+ crew = Crew(agents=[...], tasks=[...], memory=memory.memory)
167
+ with memory: # async with in async code
168
+ crew.kickoff(inputs={...})
169
+ ```
170
+
171
+ `memory.memory` is a CrewAI `Memory` (the unified memory of CrewAI 1.14 and later, which replaced its external
172
+ memory): its recall searches AmpUp Memory, so the crew's recall before each task and its own "Search memory" and
173
+ "Save to memory" tools reach it, and the raw task results CrewAI would turn into notes go into the transcript
174
+ instead. A model-call hook opens each task's turn and adds the guide and what memory has to the call's system
175
+ messages. An agent outside such a crew takes `memory.tools` (`search_memory` and `remember_memory`).
176
+
177
+ ### Pydantic AI
178
+
179
+ ```sh
180
+ pip install "ampup-memory[pydantic-ai]"
181
+ ```
182
+
183
+ ```python
184
+ from pydantic_ai import Agent
185
+ from ampup_memory.integrations.pydantic_ai import MemoryCapability, PydanticAIMemory
186
+
187
+ agent = Agent(model, deps_type=PydanticAIMemory, capabilities=[MemoryCapability()])
188
+ memory = PydanticAIMemory() # one per conversation, as the run's deps
189
+ async with memory:
190
+ result = await agent.run("...", deps=memory)
191
+ ```
192
+
193
+ The agent is made once; each conversation's memory travels in `deps` (a `PydanticAIMemory`, or your own deps with
194
+ one as `memory`). `MemoryCapability` is `memory_instructions` (a dynamic instruction: the guide and what memory has
195
+ for the run's prompt), `memory_toolset` and the run's output for the transcript; the first two also work alone, as
196
+ `Agent(instructions=memory_instructions, toolsets=[memory_toolset])`, with `memory.did(str(result.output))`.
197
+
198
+ ### LiteLLM proxy
199
+
200
+ ```sh
201
+ pip install "ampup-memory[litellm]"
202
+ ```
203
+
204
+ ```yaml
205
+ # config.yaml
206
+ litellm_settings:
207
+ callbacks: ampup_memory.integrations.litellm.callback
208
+ ```
209
+
210
+ ```sh
211
+ AMPUP_MEMORY_LITELLM_RECALL=1 litellm --config config.yaml
212
+ ```
213
+
214
+ An app that only points its OpenAI-compatible client at the proxy gets a memory session per conversation: each chat
215
+ completion that succeeds is a turn (advice is asked for each user message), and the session ends with its transcript
216
+ once the conversation has been idle for `AMPUP_MEMORY_LITELLM_IDLE_SECS` (600 by default) or the proxy stops. With
217
+ `AMPUP_MEMORY_LITELLM_RECALL=1`, what memory has for the user's message is added to the request's system message
218
+ before it goes to the model. A conversation is what the request names (`litellm_session_id`, or
219
+ `metadata.session_id`), else its key, `user` and first user message. The app has no memory tools, so what it gets back is what
220
+ other apps' agents remembered and, where the server keeps them, preferences from what users type.
221
+
222
+ ### Any other framework
223
+
224
+ `ampup_memory.integrations.Conversation` is what the adapters drive: `recall(prompt)` (the text to add to the
225
+ model's context for the turn the user's message opens), `did(text)` (the answer, for the transcript), `search` and
226
+ `remember` (the tools), and `end(outcome, reward)`; each with an `a`-prefixed async twin. `GUIDE` is the line that
227
+ tells the model when to use the tools (`guide(search, remember)` names them as your framework does). `Conversations`
228
+ holds many at once by a key, for a host that serves many conversations from one object.
229
+
230
+ ## Serving many tenants (platforms)
231
+
232
+ A platform (an app that serves many customers of its own) uses one platform key for all of them. Each request names
233
+ the tenant, by the platform's own id for that customer, and, optionally, the user acting in it. Memory creates a
234
+ tenant the first time a request names it and enrolls a user the same way; each tenant's memory, and what it learns,
235
+ stays inside it.
236
+
237
+ ```python
238
+ platform = AmpUpMemory("https://memory.example.com", "msk_...") # the platform key, on your server only
239
+
240
+ # Per request: a copy for that tenant and user. Copies share the connections; close only `platform`.
241
+ mem = platform.for_tenant("acme", name="Acme Corp").for_user("u_42", email="pat@example.com", name="Pat Lee")
242
+ run = mem.session("Draft the renewal email", harness="renewal-writer")
243
+ mem.ingest([{"source": "crm:note:9", "body": "...", "occurred_at": micros(datetime.now(timezone.utc)), "acl": ["user:u_42"]}])
244
+
245
+ platform.tenants.ensure("acme", name="Acme Corp") # {tenant, org, created}
246
+ platform.tenants.list(limit=100) # the platform's tenants and their usage
247
+ platform.tenants.forget_user("acme", "u_42") # a user leaves
248
+ platform.tenants.delete("acme") # purge the tenant; {purging: true} until it is done
249
+ ```
250
+
251
+ Or pass `tenant=`, `tenant_name=`, `user=`, `user_email=` and `user_name=` to the constructor. Tenant and user ids
252
+ are the platform's own: 1 to 128 printable ASCII characters, case-sensitive. Email and name are stored on the user
253
+ and kept up to date, never their identity. Names and emails can be any text: the client sends them percent-encoded
254
+ (UTF-8). A tenant's name only labels it when it is created. Without a user, a request is the tenant's own: it can
255
+ ingest and read what the whole tenant shares, but sessions, advice, `remember` and `forget` need a user. ACLs on
256
+ what the platform writes name its users as `user:<user id>` and the whole tenant as `group:all`.
257
+
258
+ Name each of your agents' sessions with its own `harness`, never one ending in `:sdk`: advice isn't learned from
259
+ those.
260
+
261
+ ## Methods
262
+
263
+ | Method | Route | Returns |
264
+ |---|---|---|
265
+ | `AmpUpMemory(server, token, *, org, team, tenant, tenant_name, user, user_email, user_name, timeout)` | | `token` may be `None` for a local server |
266
+ | `AmpUpMemory.from_profile(context=None)` | | a client for a CLI context |
267
+ | `AmpUpMemory.connect()` | | the memory this machine's agents use (see [Agent frameworks](#agent-frameworks)) |
268
+ | `for_tenant(tenant, *, name=None)` | | a copy for another tenant, as the tenant itself |
269
+ | `for_user(user, *, email=None, name=None)` | | a copy for another user of the same tenant |
270
+ | `me()` | `GET /me` | who you are: user, groups, scope, memberships |
271
+ | `ingest(episodes)` | `POST /ingest` | every episode id; sent in batches of 500; needs an ingest or admin key |
272
+ | `remember(source, body, *, acl, document)` | `POST /remember` | `{episode_id, scope, readers}`, or `{queued, message}` |
273
+ | `forget(episode_id)` | `POST /forget` | the forgotten id |
274
+ | `search(query, k=10)` | `POST /search` | a list of fact hits |
275
+ | `query(q)` | `POST /query` | a query-language result (`find`: entities, facts, count, changes, passages, schema, metrics) |
276
+ | `episode(episode_id)` | `POST /episode` | the episode's text, or `None` |
277
+ | `session(task, *, harness)` | `POST /sessions` | a `Session`: `id`, `task`, `opening` (the advice served at its start) |
278
+ | `Session.advice(question=None, *, moment, conversation)` | `POST /advice` | advice for the task or the step at hand, recorded in the session |
279
+ | `Session.end(outcome, reward, *, transcript, reason)` | `POST /sessions/end` | `{ended, served, session_id}` |
280
+ | `advice(question)` | `POST /advice` | advice outside any session |
281
+ | `call_tool(name, arguments)` | `POST /mcp` | one of the server's MCP tools (`start_session`, `get_advice`, `search_memory`, ...): its text |
282
+ | `reward(run_id, reward, reason=None)` | `POST /runs/reward` | the id; rewards an ended session (written within a minute of its end) or a run |
283
+ | `tenants.ensure(tenant, name=None)` | `PUT /tenants/{tenant}` | `{tenant, org, created}` |
284
+ | `tenants.get(tenant)` | `GET /tenants/{tenant}` | `{tenant, org, created_at, limits, usage}`; 404 if unknown |
285
+ | `tenants.list(after=None, limit=None)` | `GET /tenants` | a page of the platform's tenants with usage (up to 500) |
286
+ | `tenants.delete(tenant)` | `DELETE /tenants/{tenant}` | purges the tenant; `{purging: true}` while it runs |
287
+ | `tenants.forget_user(tenant, user)` | `POST /tenants/{tenant}/users/{user}/forget` | forgets the user and what they wrote |
288
+ | `micros(datetime)` | | `occurred_at` in microseconds since the epoch |
289
+
290
+ Every failure raises `AmpUpMemoryError` with `status`, `message` and, on a 429, `retry_after`. An error the
291
+ server reports inside a row (a bad query, say) raises it too, with status 200.
292
+
293
+ The TypeScript client with the same methods is [`ampup-memory`](https://github.com/A79-ai/ampup-memory/tree/main/sdk/typescript).
294
+
295
+ ## License
296
+
297
+ Apache-2.0.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ampup-memory"
3
- version = "0.3.1"
3
+ version = "0.3.3"
4
4
  description = "A thin Python client for an AmpUp Memory server: team memory for coding agents"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -15,6 +15,15 @@ classifiers = [
15
15
  "Typing :: Typed",
16
16
  ]
17
17
 
18
+ [project.optional-dependencies]
19
+ claude-agent-sdk = ["claude-agent-sdk>=0.2"]
20
+ openai-agents = ["openai-agents>=0.26"]
21
+ langgraph = ["langchain>=1.0", "langgraph>=1.0"]
22
+ google-adk = ["google-adk>=2.15"]
23
+ crewai = ["crewai>=1.15"]
24
+ pydantic-ai = ["pydantic-ai-slim>=2.77"]
25
+ litellm = ["litellm[proxy]>=1.111"]
26
+
18
27
  [project.urls]
19
28
  Homepage = "https://github.com/A79-ai/ampup-memory"
20
29
  Source = "https://github.com/A79-ai/ampup-memory/tree/main/sdk/python"