> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anonalabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Agent Framework

> Persistent memory for Microsoft Agent Framework agents.

Agent Framework has a first-class extension point for context:
`ContextProvider`. Anona implements it, so memory is injected before every
`agent.run()` call and the turn is stored after, with no vector database and no LLM
key of your own.

```bash theme={null}
pip install 'anona[msagent]'
```

<Note>
  This installs `agent-framework-core`, the lean package this adapter
  actually imports, not the full `agent-framework` meta package, which
  additionally pulls in every vendor integration the framework ships (Azure,
  Anthropic, Bedrock, Redis, and more). If your project already depends on
  `agent-framework` for a real chat client, you already have everything this
  adapter needs.
</Note>

## Setup

```python theme={null}
from agent_framework import Agent
from anona.integrations import MemoryBridge
from anona.integrations.ms_agent import AnonaContextProvider

bridge = MemoryBridge(api_key="anona_live_...", space_id="assistant")

agent = Agent(
    client=chat_client,
    instructions="You are a helpful assistant.",
    context_providers=[AnonaContextProvider(bridge=bridge)],
)

response = await agent.run("What's the weather in Paris?")
```

That's the whole integration. `context_providers=[...]` is all the wiring
this needs. `agent.run(...)` calls this adapter automatically, before and
after every run, including runs where the model calls a tool one or more
times before answering.

## What actually happens on a turn

* **Before the model runs**, the adapter searches Anona for the current
  turn's question and appends the result to the agent's instructions. It is
  appended, never a replacement: your own `instructions=` text always
  reaches the model, with Anona's block added after it.
* **After the model responds**, the adapter stores the turn: your question
  and the model's final answer.
* Both happen **exactly once per `agent.run()` call**, no matter how many
  times the model calls a tool along the way. A tool-calling turn still
  produces exactly one memory search and one stored memory, not one per
  model step.

## Scoping

```python theme={null}
bridge = MemoryBridge(
    api_key="anona_live_...",
    space_id="assistant",
    user_id="customer-42",
)
```

Memories written under one `user_id` are only ever returned to that user, so
a single space can back every customer of your app. Set `user_id`/`agent_id`/
`session_id` when you construct `MemoryBridge`, because Agent Framework's own
session object doesn't carry a stable per-user identity to forward
automatically, so scope here is fixed once, at construction time.

<Note>
  If you don't pass your own `session=` into `agent.run(...)`, Agent
  Framework creates a new session (and a new random session ID) on every
  call. That's fine: this adapter doesn't depend on session persistence for
  memory to work across turns; Anona already keeps continuity through your
  `space_id`/`user_id` scope, independent of whatever the framework does
  with sessions.
</Note>

## Turning off writes

```python theme={null}
AnonaContextProvider(bridge=bridge, record=False)
```

Keeps recall, skips storing new turns.

## Failure behaviour

If Anona is unreachable, the provider contributes no instructions and the
agent runs normally. Failures are logged, never raised.
