Documentation Index
Fetch the complete documentation index at: https://docs.egisai.co/llms.txt
Use this file to discover all available pages before exploring further.
set_context() writes to a ContextVar, so async tasks and child threads
inherit the value cleanly without leaking across requests.
When to use it
Useset_context() for:
- Multi-tenant attribution — pass the end-customer’s
user_idandsession_idper request so each audit event identifies who triggered it. - Sub-agents — name a logical sub-agent (
agent="billing-bot") so calls from this section of code show up as a distinct Agent on the dashboard. - Workflows — group related calls with a
workflow_id.
app= argument on egisai.init() is enough.
Parameters
End-customer or end-user identifier for multi-tenant attribution.
Recorded on each audit event for the lifetime of the context.
Optional role label for the user (e.g.
"admin", "customer"). Free-form.Logical sub-agent name. The first time the SDK sees a new name it
registers it as an Agent on the platform; subsequent uses are cache hits.Wins over the process-level
app from egisai.init() and over auto-detected
identity for the duration of the context.Direct UUID escape hatch for callers that already know the platform’s
internal Agent ID and don’t want a name-resolution round-trip.Most users should prefer
agent= and let the SDK resolve the ID.End-user session identifier. Useful for grouping conversation turns on the
dashboard.
Identifier for an orchestration step or batch job. Lets you correlate
related calls on the dashboard.
Passing
None for any field leaves the existing value alone. To clear a
field, set it to an empty string.Returns
None. The active context is updated in place.
Examples
Multi-tenant FastAPI handler
Multiple sub-agents in one process
Workflow correlation
Resolution precedence
When attributing a call, the SDK uses:set_context(agent_id=...)(explicit UUID).set_context(agent=...)(resolved name).- System-prompt fingerprint (auto-detected sub-agent).
- The process-level
app=fromegisai.init().
set_context calls always win.
What’s next
Multi-agent context
Patterns for several sub-agents in one process.
Agents
The mental model behind agent identity.