config.yaml by default. Use Agent parameters to give individual agents their own models, endpoints, and credentials
Set the model for a single agent
Complete installation, then select one platform configuration below. Enable the model in the corresponding account, or replace its name with an accessible model or inference endpoint- Volcengine
- BytePlus
main.py
python main.py to print a response. If all agents share the settings above, Agent(name="assistant") is sufficient
Model parameters and global settings
Explicit constructor arguments override their corresponding global settings. Unspecified fields retain global values. VeADK searches forconfig.yaml from the current directory upward, and existing environment variables take precedence over matching file settings. See quickstart for YAML configuration
Without global overrides, Volcengine uses
doubao-seed-2-1-pro-260628 at https://ark.cn-beijing.volces.com/api/v3/. With CLOUD_PROVIDER=byteplus, the defaults are seed-2-0-lite-260228 and https://ark.ap-southeast.bytepluses.com/api/v3. Check existing MODEL_AGENT_* variables when switching platforms so settings from the previous platform are not retained
Resolve an API key by name
Key precedence is: nonemptymodel_api_key, MODEL_AGENT_API_KEY, a lookup using model_api_key_name or MODEL_AGENT_API_KEY_NAME, then the account’s default key lookup
Rate-limit retries
With the defaultadk runtime, Responses disabled, and no custom model, VeADK retries an HTTP 429 once if no model response has been emitted. A valid numeric Retry-After controls the delay, capped at 2 seconds; missing or invalid values use 0.5 seconds. This retry layer does not replay a request after output has started
Configure fallback models
SetBACKUP_MODEL_NAME in addition to the earlier settings, then replace the agent definition with:
model_fallbacks=["backup-model-name"]. When both are configured, candidates from model_name precede those from model_fallbacks
Same-provider name fallbacks are available for the default model API and Responses API. Every candidate must support the request’s tools, input modalities, and output format. Fallbacks handle request failures; low-quality answers do not automatically trigger a switch
Configure cross-provider fallback models
UseModelFallbackEndpoint when a backup has a different provider, endpoint, or credentials. In addition to the primary settings, set BACKUP_MODEL_NAME, BACKUP_MODEL_PROVIDER, BACKUP_MODEL_API_BASE, and BACKUP_MODEL_API_KEY to the backup service’s actual values
fallback.py
ModelFallbackEndpoint parameters
Dictionaries can replace endpoint objects. Supported aliases are
model, provider, api_base or base_url, api_key, api_key_env, and extra_config. Explicitly specify the provider, endpoint, and credentials across providers to avoid inheriting unsuitable settings
Fallback limitations
enable_responses=Trueaccepts only same-provider string fallbacks; endpoint objects or dictionaries fail at initializationcodexandpiagentignore fallback chains; useadkwhen fallbacks are required. See runtime- With a custom
modelobject in the default runtime,model_fallbacksis ignored; configure fallbacks on that object instead
Query routing
SystemOne selects a model once at the start of each user turn, using the effective history, instructions, tool declarations and candidate capabilities. The selection remains fixed through tool loops, nested AgentTool calls and sub-agent transfers. The next user turn is classified again. Routing is disabled unless explicitly configured; an unconfigured project retains its original execution behavior.Configuration
Add the block toconfig.yaml in the project root:
config.yaml
config.yaml in the current working directory and its parents at startup, so no extra code is needed:
agent.py
Agent(query_routing={...}), or disable routing explicitly with query_routing=False.
Parameters
Shared decision connection
The rootdecision block is shared by query routing and content safety. It enables neither feature. Agent(decision=DecisionConfig(...)) supplies explicit immutable connection values; each consumer owns its client and questions. Configure connections only here, not inside either feature.
DECISION_API_URL, DECISION_API_KEY, and DECISION_MODEL override YAML. Overriding a configured destination requires its own DECISION_API_KEY. Explicit DecisionConfig values bypass file/environment loading. Questions, thresholds, and decision_timeout belong to each feature; changing routing policy does not change content-safety policy.
Candidate model capabilities
Eachsimple_models entry can declare capabilities; anything not declared is treated as unsupported:
Built-in questions and thresholds
Control questions always use thenoul type. Four questions are built in:
The default thresholds are
0.5 for complex reasoning, tool orchestration and long context, and 0.05 for high stakes. Explicit builtin_thresholds values take precedence; custom questions still default to 0.15 when their threshold is omitted. A threshold bounds the SystemOne question probability, not the task error rate. These defaults apply only when routing is enabled; shadow mode still executes with the strong model.
A custom question only needs question and threshold; its ID is generated as custom_1, custom_2, and so on. Built-in IDs are reserved and cannot be overridden. Every question returns a probability from 0 to 1; the simple model is used only when all probabilities are at or below their thresholds. Any probability above its threshold, a missing or invalid answer, a Decision timeout, or a Decision error routes the request to the strong model. Incomplete decision input, unsupported media or unavailable dynamic tool declarations also select the strong model. Effective history is never silently truncated to enable a downgrade. After selection, a provider failure propagates and never triggers a model switch. A transient failure (timeout, connection error, 429, or 5xx) excludes the simple model from selection for a 60-second cooldown, so subsequent turns use the strong model until it expires. Other 4xx responses are request-specific and do not open the cooldown. Late capability growth fails explicitly.
Tool argument validation in enforce mode
In enforce mode, tool arguments are validated against the tool’s declared schema before execution. Unambiguous decimal integer strings can be converted losslessly when the schema explicitly requires an integer; fractions, booleans, and ambiguous formats are not coerced to integers. Invalid arguments return a structured error without original argument values for correction by the model already selected for this turn. At most two correction responses are allowed across the root turn, including nested agents; further invalid calls fail explicitly. Tools that have already executed are not automatically retried. Tools without parameter schemas retain their existing behavior. Validator-infrastructure failures, such as a schema that cannot be built or a non-local$ref/$dynamicRef, are logged and skip validation for that invocation instead of blocking the tool call. Disabled routing, shadow mode, and turns that select the strong model preserve the original tool argument behavior.
Responses continuation and routing
Responses continuation is reused only when the target, endpoint, identity, request configuration and effective history match. Model changes, including A → B → A, rebuild the chain from full business history; expired IDs retry with that history on the same model. Provider-specific reasoning and signatures are not replayed to a different target.enable_responses_cache=False always sends full history. Server-side caching still requires the provider’s cache-service entitlement; Responses continuation can also use store=True with extra_body={"caching": {"type": "disabled"}}.
Nested agents and lifecycle
Nested AgentTool calls retain separate sessions and inherit one root decision. Native ADK LlmAgent and standard sub-agent workflows are adapted on owned copies; custom native LlmAgent subclasses must implement turn binding explicitly. Resume uses the decision persisted under a per-router-agent key; independently configured routed agents reached by native transfer in the same invocation each keep their own record instead of overwriting one another, and a configuration change to the same routed agent still fails explicitly. The decision HTTP client is closed with the Agent/Runner lifecycle instead of being rebuilt after every continuation. Live bidirectional execution and external runtimes are outside this ADK text-turn contract. Concurrent execution of the same session still requires application-level serialization; cross-process simultaneous classification is not a distributed lock. Model events exposeveadk_query_routing metadata with root turn ID, route, model and target digest. The decision event also includes reason, latency and reported input tokens. Credentials and raw query text are excluded.
Full example
agent.py
Responses API
The Responses API supports conversation continuation, multimodal input, and structured output. Confirm that the model and endpoint support the Ark Responses protocol. An OpenAI-compatible endpoint does not automatically support every feature described hereEnable
Requiresgoogle-adk>=1.34.0. After configuring the model, set Agent(enable_responses=True); the feature is disabled by default. For BytePlus, select an available model and endpoint that explicitly support the required capabilities; the flag alone does not add support
Multimodal input
FileData.file_uri accepts the following sources. Set mime_type to match the content:
Local files are sent to the model service. Confirm that they are suitable for upload and check supported formats and size limits before running the example
example.png in the current directory, then run python image_reader.py:
image_reader.py
types.Part, alongside file_data. This fragment can replace the image Part; the service determines the supported frame-rate range:
Configure Ark context management
For models supportingcontext_management, pass settings through model_extra_config. This fragment requests removal of older thinking content while retaining the most recent thinking turn:
Context caching
Responses caching is enabled by default. Cache hits depend on the service and request content; reduced usage is not guaranteed. Setenable_responses_cache=False to disable it
In event usage_metadata, cached_content_token_count counts cached input tokens and prompt_token_count counts total input tokens. Calculate their ratio only when the latter is greater than zero. Read events with Runner.run_async to inspect usage
When output_schema is configured, VeADK removes cache settings that conflict with structured output. See structured output