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

# Inject Context • AI Agent SDK

> inject_context: Write the active span context into ``carrier`` as W3C headers.

# inject\_context

<div className="flex items-center gap-2">
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**GatewayTraceHook**](../classes/GatewayTraceHook) class in the [**protocols**](../modules/protocols) module.

Write the active span context into `carrier` as W3C headers.

Called at an egress boundary (LLM / MCP / HTTP-tool request) so the
downstream service's spans nest under the current agent turn. A no-op
when no exporter is attached, leaving `carrier` untouched.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def inject_context(carrier: 'MutableMapping[str, str]') -> None
```

## Parameters

<ParamField query="carrier" type="'MutableMapping[str, str]'" required={true}>
  No description available.
</ParamField>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L5228">
  `praisonaiagents/gateway/protocols.py` at line 5228
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Context Concept" icon="layer-group" href="/docs/docs/concepts/context" />

  <Card title="Context Management" icon="sliders" href="/docs/docs/features/context-management" />

  <Card title="Context Strategies" icon="diagram-project" href="/docs/docs/features/context-strategies" />
</CardGroup>
