Workspace Context Integration enables ambient intelligence by automatically detecting and syncing the user’s current work environment to agent systems. This allows AI agents to provide contextually relevant suggestions, smart defaults, and page-aware assistance without requiring explicit user input.Unlike user-initiated interactions, workspace context operates passively in the background, continuously monitoring the application state and making it available to both frontend and backend agent systems.
Ambient intelligence means the system understands:
Where you are: Current page, active view, focused artifact
What you’re working on: Selected portfolio, date range, active workbook
What you can do: Available actions based on current context
Your preferences: User settings that affect agent behavior
This contextual awareness enables agents to offer proactive insights, pre-fill requests with relevant data, and filter tool availability based on the current page.
# Automatic extraction in agent backend@app.post('/api/chat')async def chat(request: Request, data: AgentRequest): # Extract from headers workspace_header = request.headers.get('X-Workspace-Context') workspace_context = json.loads(workspace_header) if workspace_header else None # Extract from request body if not workspace_context: workspace_context = data.workspace # Use in tool execution tools_with_context = bind_tools_with_context(tools, workspace_context)
Tools can declare their required context to control availability:
Tool Definition
Agent Tool Selection
Copy
@tool("update_spreadsheet")def update_spreadsheet( cell: str, value: str, config: Optional[RunnableConfig] = None) -> Dict[str, Any]: """ Update a cell in the active spreadsheet. REQUIRED CONTEXT: - current_view: 'workbook' - workbook_id: Must be present This tool is only available when user is viewing a workbook. """ workspace_context = extract_workspace_context(config) if not workspace_context or workspace_context.current_view != 'workbook': return { "error": "This action requires an active workbook", "suggestion": "Please open a workbook first" } if not workspace_context.workbook_id: return { "error": "No workbook ID detected", "suggestion": "Ensure you have a workbook open" } # Perform update... return {"success": True}
Copy
# app/agent/core/tool_selector.pyfrom typing import Listfrom app.models.workspace import WorkspaceContextdef filter_tools_by_context( tools: List[Tool], workspace_context: Optional[WorkspaceContext]) -> List[Tool]: """Filter tools based on current workspace context""" if not workspace_context: return tools available_tools = [] for tool in tools: # Check if tool requires specific view required_view = tool.metadata.get('required_view') if required_view and workspace_context.current_view != required_view: continue # Check if tool requires artifact ID required_artifact = tool.metadata.get('required_artifact') if required_artifact: if required_artifact == 'workbook' and not workspace_context.workbook_id: continue if required_artifact == 'dashboard' and not workspace_context.dashboard_id: continue if required_artifact == 'workflow' and not workspace_context.workflow_id: continue available_tools.append(tool) return available_tools
Context enables automatic pre-filling of common parameters:
Copy
@tool("query_portfolio_holdings")def query_portfolio_holdings( portfolio_id: Optional[str] = None, date: Optional[str] = None, config: Optional[RunnableConfig] = None) -> List[Dict]: """ Query portfolio holdings. SMART DEFAULTS: - portfolio_id: Uses selected portfolio if not specified - date: Uses selected date if not specified """ workspace_context = extract_workspace_context(config) # Smart default: Use selected portfolio if not portfolio_id and workspace_context: portfolio_id = workspace_context.selected_portfolio_id if portfolio_id: logger.info(f"Auto-detected portfolio: {workspace_context.selected_portfolio_name}") # Smart default: Use selected date if not date and workspace_context: date = workspace_context.selected_date if date: logger.info(f"Auto-detected date: {date}") # Validate required params if not portfolio_id: return { "error": "Portfolio ID required", "suggestion": "Select a portfolio or specify portfolio_id parameter" } # Execute query with smart defaults...
def validate_context_permissions( workspace_context: WorkspaceContext, user_id: str) -> bool: """Ensure user has access to context artifacts""" if workspace_context.workbook_id: if not user_has_workbook_access(user_id, workspace_context.workbook_id): raise PermissionError("User cannot access this workbook") if workspace_context.selected_portfolio_id: if not user_has_portfolio_access(user_id, workspace_context.selected_portfolio_id): raise PermissionError("User cannot access this portfolio") return True