Query Execution Flow
This page explains how a Query is executed in the ARK platform, from creation to completion.
Overview
When you create a Query resource, it triggers a hierarchical execution flow:
- Query - Created by user with input and targets
- Query Controller - Orchestrates the execution
- Agents or Teams - Process the query
- Teams use strategies to coordinate multiple agents
- Agents execute prompts against models
- Models - Generate responses and can invoke:
- Tools - Custom functions
- MCP Servers - External service integrations
- Optional Components:
- Memory - Provides conversation context
- Execution Engines - Custom implementations for queries, agents, or teams
Execution Steps
1. Query Creation
A user creates a Query resource specifying:
- input: The user’s question or request
- targets: One or more Agents or Teams
- memory (optional): Reference to a Memory resource
- sessionId (optional): Conversation session identifier
- serviceAccount (optional): For RBAC isolation
apiVersion: ark.mckinsey.com/v1alpha1
kind: Query
metadata:
name: my-query
spec:
input: "What is the weather today?"
targets:
- type: agent
name: weather-agent
memory:
name: conversation-memory
2. Controller Processing
The Query controller detects the new Query and:
- Creates an impersonated Kubernetes client using the specified service account
- Resolves the Memory reference (if provided)
- Determines the execution strategy based on targets
- Initiates execution for each target
3. Target Execution
For each target (Agent or Team):
Agent Execution
- Model Resolution: Resolves the agent’s model reference
- Prompt Construction: Builds the final prompt from:
- Agent’s system prompt
- Memory context (if configured)
- User input
- Tool Preparation: Prepares available tools and MCP servers
- Model Invocation: Sends request to the model provider
- Tool Execution: Handles any tool calls from the model
- Response Generation: Collects and formats the final response
Team Execution
- Strategy Application: Uses the team’s strategy (sequential, parallel, etc.)
- Member Coordination: Orchestrates execution across team members
- Result Aggregation: Combines responses according to strategy
4. Response Handling
The controller:
- Collects responses from all targets
- Updates the Query status with results
- Stores conversation in Memory (if configured)
- Marks the Query as completed
Execution Engines
Custom execution engines can override default behavior at different levels:
- Query Engines: Custom query processing logic
- Agent Engines: Custom agent execution (e.g., LangChain, AutoGen)
- Team Engines: Custom team coordination strategies
Error Handling
The system handles errors gracefully:
- Model Errors: API failures, rate limits, invalid responses
- Tool Errors: Tool execution failures, timeouts
- Resource Errors: Missing agents, models, or tools
- Permission Errors: RBAC violations, service account issues
Failed queries are marked with error status and detailed error messages.
Observability
Query execution is fully observable through:
- Kubernetes Events: Resource creation and status changes
- OpenTelemetry Traces: Detailed execution spans
- Logs: Structured logging throughout the pipeline
- Metrics: Performance and error metrics
Example Flow
Here’s a complete example of a weather query execution:
- User creates Query targeting
weather-agent
- Controller resolves
weather-agent
and itsgpt-4
model - Agent constructs prompt with weather tools available
- Model calls
get-weather
tool with location parameter - Tool executes and returns weather data
- Model generates natural language response
- Controller updates Query with final response
- Memory stores conversation for future context
This flow demonstrates ARK’s orchestration of multiple components to deliver intelligent, tool-enabled responses.
Last updated on