Hi AgentOS community,
I’m working on implementing context-aware AI agents using AgentOS and would like to get feedback on the best architectural approaches for injecting business context into agents at runtime.
Current Setup
-
FastAPI application integrated with AgentOS
-
Multi-tenant SaaS architecture with request-scoped business context
-
Middleware that extracts business context from request headers (user_id, customer_id, business_unit_id, etc.)
-
Context stored in request.state.context as a structured object
Goal
I want my AI agents to have access to the current request’s business context so they can make context-aware decisions and API calls. For example:
-
Filter data based on the current user’s permissions/scope
-
Make API calls with the appropriate tenant/customer context
-
Provide responses relevant to the user’s specific business unit
-
Maintain proper data isolation in multi-tenant scenarios
Current Approach - Input Schema Method
I’m currently experimenting with using a custom input schema to inject context:
class BusinessContextInput(BaseModel):
message: str = Field(..., description="User's message")
context: Optional[Dict[str, Any]] = Field(None, description="Business context")
agent = Agent(
name="ContextAwareAgent",
model=model,
tools=tools,
instructions=instructions,
input_schema=BusinessContextInput
)
Then in my FastAPI endpoint, I would populate the context field with the business context extracted by middleware.
Questions
-
Is the input schema approach the recommended way to inject runtime context into agents?
-
Are there performance implications of passing context through the input schema for every request?
-
Does this approach work well with AgentOS’s conversation memory and session management?
-
-
Alternative Approaches:
-
Should I be using agent-level context injection instead?
-
Is there a way to set context on the agent instance dynamically before each conversation?
-
Would custom tools that have access to request context be a better approach?
-
-
Agent Instructions and Context:
-
How should I modify agent instructions to make use of the injected context?
-
Should context be part of the system instructions or passed as user message metadata?
-
-
Session Management:
-
How does business context interact with AgentOS’s session management?
-
Should each user/tenant have separate agent instances or sessions?
-
How do I ensure context doesn’t leak between different users’ sessions?
-
-
Tools and Context:
-
What’s the best way to make business context available to custom tools?
-
Should tools receive context as parameters, or access it through some other mechanism?
-