microsoft / microsoft/agent-framework
Python: [Bug]: Code Interpreter file citations are lost through FoundryToolbox hosting
@TaoChenOSU is already working on this.
Since Aug 31, 2026.
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 2.3k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 358
Description
### Description
## Summary
When an Agent Framework agent invokes Code Interpreter through a Foundry `FoundryToolbox`, Code Interpreter creates the requested file, but the hosted Responses API does not return a native `container_file_citation`. The customer therefore receives no `container_id` or `file_id` and cannot download the generated file through the container-files API.
## Reproduction
1. Configure a Foundry Toolbox with a `code_interpreter` tool
2. Create an Agent Framework agent using `FoundryToolbox` and `ResponsesHostServer`
3. Ask the agent to write `/mnt/data/result.txt` and attach it
4. Invoke the hosted agent through its Responses endpoint
5. Inspect the response output and message annotations
## Observed behavior
The hosted response exposes the tool result as a regular `function_call_output`, with no file citation. However, a direct MCP `tools/call` to the same Toolbox returns the required metadata on the text content block:
```json
{
"type": "text",
"text": "...",
"_meta": {
"container_id": "cntr_...",
"container_file_citations": "[{\"file_id\":\"cfile_...\",\"filename\":\"result.txt\",\"container_id\":\"cntr_...\"}]"
}
}
```
This indicates that Code Interpreter and the Toolbox service produce the artifact identifiers, but Agent Framework does not carry them through to the hosted Responses output. In the Python path, per-content MCP `_meta` appears to be dropped during MCP result conversion. The hosting adapter also has no conversion from this metadata to a Responses `container_file_citation` annotation.
## Expected behavior
Agent Framework should preserve the per-content metadata and emit an annotation equivalent to:
```json
{
"type": "container_file_citation",
"container_id": "cntr_...",
"file_id": "cfile_...",
"filename": "result.txt"
}
```
### Code Sample
```markdown
import asyncio
import os
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient
from agent_framework_foundry_hosting import FoundryToolbox, ResponsesHostServer
from azure.identity import DefaultAzureCredential
async def main():
credential = DefaultAzureCredential()
agent = Agent(
client=FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
credential=credential,
),
instructions=(
"Use Code Interpreter when asked to create a file. Write files to "
"/mnt/data and attach them to the response."
),
tools=FoundryToolbox(credential),
default_options={"store": False},
)
await ResponsesHostServer(agent).run_async()
if __name__ == "__main__":
asyncio.run(main())
services:
agent-tools:
host: azure.ai.toolbox
uses:
- ai-project
tools:
- type: code_interpreter
name: code_interpreter
repro-agent:
host: azure.ai.agent
project: src/repro-agent
uses:
- ai-project
- agent-tools
protocols:
- protocol: responses
version: 2.0.0
environmentVariables:
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
- name: TOOLBOX_NAME
value: agent-tools
```
### Error Messages / Stack Traces
```markdown
```
### Package Versions
agent-framework-core==1.10.0 agent-framework-foundry==1.8.2 agent-framework-foundry-hosting==1.0.0a260630 mcp==1.28.0
### Python Version
Python 3.14
### Additional Context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.