Skip to main content

Overview

Import path: from veadk.tools.builtin_tools.create_agent import CreateAgentToolset CreateAgentToolset is a built-in toolset that lets a main agent collect available resources at runtime, create one or more sub-agents on demand, and transfer control to a chosen sub-agent through the Google ADK transfer_to_agent event. The sub-agent continues in the same session context and produces the final answer. The toolset exposes two tools:
Resources returned by collect_resources are candidates only and are not mounted automatically. The main agent must explicitly include each resource ref it wants to use in the resources list of every LLM node; when relevant skills are present in the catalog, at least one must be bound.

When to use

Use this toolset when:
  • A main agent needs to assemble sub-agents with specific skills, knowledge bases, or tools on demand, rather than fixing the sub-agent structure at development time.
  • You need to hand off a task to a dynamically created sub-agent within the same session context, where the sub-agent produces the final answer directly.
  • You need to match resources from the public Skill Hub, account Skill Spaces, knowledge bases, and built-in tools against a task.
It is not suitable when you require a strict, fixed orchestration topology — in that case declare a static sub-agent tree at development time.
In a Studio conversation, if the current session has AIO Sandbox execution environments mounted, the mounted environments take priority over dynamic sub-agent creation. The agent should first use the mounted environments (via list_envs, execute_in_sandbox, and related tools) to complete tasks, unless the user explicitly requests creating or delegating to a new agent. See Session sandbox environments.

Prerequisites

Before use:
  1. Configure the API key for the main agent’s reasoning model.
  2. To collect account-level AgentKit Skill Center skills or knowledge bases, configure Volcengine AK / SK or an STS temporary credential (use BYTEPLUS_ACCESS_KEY and friends in BytePlus mode). Public Skill Hub search does not require credentials.
  3. create_agents must run within an agent invocation driven by a Runner, otherwise it cannot register sub-agents and complete the handoff.
The public Skill Hub search is driven by keywords generated by the main agent from the task; no Space ID is required. Once AK/SK or STS credentials are configured, the AgentKit Skill Center automatically enumerates every Skill Space visible to the account. SKILL_SPACE_ID only narrows the search to a specific Space, with multiple IDs separated by commas. SKILL_HUB_SPACE_ID is retained for compatibility with legacy Skill Hub Spaces.

Usage

Add a CreateAgentToolset() instance to the Agent tools list. Describe the resource-collection, blueprint-design, and handoff flow in the agent instruction; the model decides at runtime when to call the two tools.
dynamic_agent_coordinator.py

Resource collection and matching

By default collect_resources gathers resources from the following sources and unifies them into a candidate catalog with a ref: The collection_id returned after collection must be passed unchanged to the subsequent create_agents call to associate the resource snapshot.

Offline mode

When the user prohibits external resource retrieval but allows model-service calls, the main agent can skip collect_resources and call create_agents directly with an empty string as collection_id. Every LLM node’s resources must then be an empty list, and sub-agents rely solely on their own model capabilities. No Skill Hub keyword search or resource-source calls are made in offline mode.

Agent blueprints

The agents argument of create_agents is a list of blueprints, each describing one independently constructed root agent: Nodes inside a blueprint support the following types, with availability depending on the installed Google ADK version:
The workflow node is available only on Google ADK 2.0.0 and above. On lower versions, the capability catalog returned by collect_resources indicates the supported node types, and create_agents omits workflow nodes.

Reusable identity and task separation

The name, node id, description, and instruction fields in a blueprint should describe a stable, reusable capability domain, while the task field is the sole carrier of the current one-off objective. Specifically:
  • name and id use concise snake_case capability names such as video_creation_agent, document_translation_agent, or investment_analysis_agent, not names derived from the current deliverable or research subject.
  • description and instruction describe generic operations, such as “research the user-specified subject” or “compare the user-specified candidates,” without hard-coding brands, platforms, industries, languages, or topics from the current request.
  • task preserves the complete current objective, including specific research subjects, industry information, source or target languages, and other request-specific details.
At runtime, the task context from task is automatically appended to the instruction of each LLM node, so sub-agents can complete the one-off objective without repeating request-specific entities in instruction.

LLM node

The LLM node is the most common leaf node. Its fields are:

Ad-hoc Python tools

The main agent can provide complete Python source in the python_tools of an LLM node, exposed as tools callable by the sub-agent:
Code in python_tools runs as the main agent in the current process without sandboxing. Only accept code from trusted sources, and avoid letting untrusted input become executable source directly. For small, directly enumerable or mentally verifiable problems, prefer direct reasoning by the sub-agent over creating an ad-hoc Python tool.

Parameters

Constructor parameters of CreateAgentToolset:

Limitations

  • create_agents must run within an active agent invocation driven by a Runner, otherwise it cannot register sub-agents and complete the handoff.
  • Each collect_resources result requires exactly one create_agents call that includes every required sub-agent; after it completes or sets handoff_to, it should not be called again.
  • Multiple collect_resources calls within the same session overwrite the previous resource snapshot for that session; snapshots are held in an in-process bounded cache (up to 128), and create_agents reads a snapshot without invalidating it, so the same snapshot can be reused by subsequent calls with the same request fingerprint.
  • Dynamically created sub-agents are not persisted deployments. Call await create_agent.close() when the application ends. Collecting resources again for the same session releases its previous registrations; closing a chat page does not itself guarantee connection cleanup.
  • python_tools run in the current process without sandbox isolation.

Call parameters and completion checks

“Offline mode” skips resource collection; it does not replace a cloud model with a local model. Inference may still use the network. Fully network-free execution requires a separately configured offline model and environment. Submitting all required blueprints once after collection is the recommended workflow. Request deduplication does not mean a snapshot can only be read once. A new collection replaces the current session’s snapshot; do not treat an old collection_id as a permanent resource reference. Creation results may include failed items. Inspect each results entry and the returned handoff_to; without a valid handoff target, execution has not successfully started. Custom resource_sources, leaf_factory, or knowledge_factory implementations must match the current interfaces; ordinary integrations should keep the defaults.
Last modified on September 19, 2026