Many applications run multiple logical agents inside a single Python process — a triage assistant that hands off to a billing assistant, a coding agent that delegates research to a sub-agent, a multi-tenant SaaS that has a different chatbot per customer. This page collects the patterns we recommend for attributing every call correctly.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.
The default: one Agent per process
If your process only ever runs one logical agent, there’s nothing to do beyondegisai.init():
customer-support-bot.
Several sub-agents in one process
Useegisai.set_context(agent="…") at the boundary of each sub-agent’s
execution. The first time a new name is seen the SDK registers it as an Agent
on the platform; subsequent uses are cache hits.
FastAPI / async web handler
set_context() writes to a ContextVar, so each request handler sets context
without leaking into other concurrent requests.
Multi-tenant SaaS
Attach the end-customer identity per request — separate from the agent identity — usinguser_id and session_id. Both fields land on every audit
event for the lifetime of the context.
Workflows that span multiple calls
If a single user request fans out into several model calls, group them with a sharedworkflow_id:
workflow_id so you can review a full
plan execution at once.
Threading and asyncio
set_context() uses contextvars, which means:
asynciotasks created from a context inherit the values.- Threads created with
concurrent.futures.ThreadPoolExecutorand friends inherit the values from the spawning thread. - A new top-level thread (
threading.Thread(target=...)) starts with the process-level defaults frominit(). If you need request-level context in that thread, callset_context()again at the top of its target function.
Resolution recap
When attributing a call, the SDK uses, in order:set_context(agent_id=...)— explicit UUID.set_context(agent=...)— explicit name (resolved to UUID once, then cached).- System-prompt fingerprint — auto-detected sub-agent.
app=fromegisai.init()— process-level default.
What’s next
set_context reference
Every accepted parameter.
Configuration
Init-time options.