Prepare application credentials
Use your platform Bearer token while developing. For a business backend, create an Application and issue an API key with explicit grants for the Agents, Teams or Workflows it may use. Credentials belong to the Application: replacing a key preserves access to its Sessions, while another application cannot read those Sessions simply because it uses the same Agent. Keep keys in your backend and check the business user’s permissions there. Complete deployment and create a working Managed Agent and prepare API credentials first. KeepBASE_URL, TOKEN, TENANT, NAMESPACE and AGENT_ID from those steps available. The Application owner performs these management requests:
invoke, read, interact, cancel and webhooks:write. An application key does not become a designated human approver merely because it has interact.
List and revoke old credentials
List and revoke old credentials
OLD_CREDENTIAL_ID with the old credential ID from the list. This disables that key.Create a Session and select its target
Creating a Session selects and freezes the configuration for this work; it does not submit a task. Supply a stable idempotency key when creating a Session and retain the returned ID.target.type is agent, team or workflow. Managed, External and Hosted Agents all use agent with their catalog ID; their runtime binding determines execution. Teams use a Team ID. Workflows use a definition ID and optionally a published revisionId; otherwise Service selects the latest published revision. Publishing a Workflow freezes its process definition rather than creating an application calling interface.
Use a Team or published Workflow
Use a Team or published Workflow
Grant the Team or Workflow in the credential’s
targets and fill in actual IDs. These are alternatives to creating an Agent Session. A Workflow revisionId must refer to a published revision.- Team
- Workflow
target.version to select a Managed Agent definition version. Changes become available to new Sessions while existing Sessions retain their configuration. Environment, Memory, Vault and external business data have their own access and update rules; a configuration snapshot does not freeze external data.
If the Agent needs particular credentials to access external tools, select the corresponding Vault when creating the Session or inherit the Agent’s default Vaults. The API key your application uses to call Service does not automatically authenticate tools to external systems. See Select Vaults for a Session for configuration and the vaultIds field.
Submit a Turn
Managed Agents accept a textmessage or an input array of user messages and content blocks. Teams and Workflows also accept structured business input for their task executor. Match the input to the target’s actual behavior.
202 Accepted means the task has been accepted; it may still be queued or running. After a network timeout, retry with the same Session, idempotency key and request body. Service returns the original Turn. Changing the body while reusing the key returns 409 Conflict. Use a new key only for a new task.
Turns execute sequentially within a Session. Managed Agents retain conversational context. Each Team or Workflow Turn starts an independent task: its history is collected in the Session, but a previous task’s internal execution context is not automatically inherited. Include any previous results needed by the next task in its input. Use separate Sessions for unrelated objects or parallel batches.
Restore a page and observe execution
Persist the business object, Session ID and Turn ID together. On page refresh, restore/snapshot, then subscribe to /events/stream from its as_of cursor. A refresh restores the display and must not resubmit task input. If local state survives a disconnect, reconnect from the last successfully applied event cursor.
/turns/{turnId}/snapshot and /turns/{turnId}/events/stream. Session and Turn cursors belong to separate logs and cannot be interchanged. A Session stream stays open for later Turns, so connection closure is not completion. Read the Turn status: completed is success, partial_succeeded is partial success, and failed, cancelled and timed_out are other terminal outcomes.
A Turn snapshot indexes items, tools, required_actions, steps, artifacts and usage by identifier. Managed Session snapshots also retain complete conversation, subagent and native interaction records. See the API reference for the interfaces and events and notifications for replay and callback handling.
Participate during execution
Read pending work fromrequired_actions and answer through the Turn’s /actions resource. Include request_id and, when required, expected_version. Managed confirmation answers go in payload, for example {"allow":true}. A designated human must answer using their authorized user identity; an application key cannot impersonate them.
Read the current Turn’s pending actions first. Do not call /actions if none are pending:
kind, and request. Copy its actual request_id unchanged, including prefixes such as native:. Answer the action the user selected rather than automatically allowing everything in the list.
TOKEN; external tool results may use an application key with interact scope.
- Tool confirmation
- External tool result
- Business approval
For a Managed
confirmation action, let the user inspect the tool and arguments before answering. Use allow: true to allow, or false with a reason to deny. The user must be the designated confirmer or explicitly delegated by the Managed Agent owner.202 Accepted response means the answer was received. Query the returned command ID until command.status is completed or failed. On failure, inspect command.error and reread the pending action. Retry a lost request with its original idempotency key and body.
/capabilities for the target’s supported features, then Turn /capabilities and its available_commands before showing cancellation, input or resume controls. An accepted cancellation request still needs a confirmed terminal outcome. Continue with Sessions, tasks, and budgets to learn how to add requirements, answer pending actions, and resume execution.
Credentials, budgets and notifications
ApplicationmaxConcurrent and tokenBudget apply across its keys and Sessions. Reported runtime usage drives token accounting and subsequent admission, so this is execution governance rather than a real-time hard limit on a model provider’s bill. Session creation also accepts timeoutSeconds and budget.maxTokens for each Turn. Managed Session budgets have a separate /budget resource; see Usage, subagents, and budgets for configuration and usage queries.
Set application limits and Turn budgets
Set application limits and Turn budgets
As the Application owner, read its current version before updating limits. Reread after a version conflict rather than overwriting another update.Set the timeout in seconds and token budget for each Turn when creating a new Session:
Check the deliverables
Acompleted Turn means this execution finished successfully. The application still needs to check that the deliverables meet its business requirements: a report may need sources, a file must be downloadable, and a structured result must contain the data required for further processing. For file output, use the interfaces in Files and artifacts to retrieve the actual artifact rather than treating a filename in the Agent’s reply as proof of delivery.
Optional inputSchema, outputSchema and resultMapping settings are frozen when creating the Session. Verify real target output before defining mappings or validation. JSON written inside an Agent’s text reply is not automatically a structured business result. These rules validate data shape; they do not assess content quality or automatically make the Agent revise its output.
Validate structured input and results
Validate structured input and results
This assumes a published Workflow accepts
{topic} and actually returns {answer}. Adapt the schemas and JSON Pointer to real target data; /answer selects a structured result field. Grant this Workflow to the application credential first.SDK and runnable examples
PythonServiceClient wraps the same API:
agentscope-service/service-controlplane/examples/service-api contains runnable registration and calling examples for Agents, Teams and Workflows. Use ManagementClient for configuration and ServiceClient for application execution. See the API reference for interface entry points.