Get the full Managed Agents workflow running in five minutes: create an Agent and Environment, open a Session, submit a task, and stream the results.
Prerequisites
- You have activated Model Studio and created an API Key (
sk-xxx), and obtained your workspace ID (ws_xxxxxxxxxxxx). For details, see Overview and authentication. - Export the API Key and Endpoint as environment variables. The following examples reference them directly:
Workflow
A complete task execution consists of five steps:
- Create an Agent: Define the model and system prompt to obtain an
agent_xxx. An Agent is typically created once and reused. - Create an Environment: Define the runtime environment to obtain an
env_xxx. An Environment is typically created once and reused. - Create a Session: Bind an Agent to an Environment to obtain a
sesn_xxx. Create a new Session for each task. - Send an Event: Submit a task instruction to the Session, which triggers the Agent to enter the
runningstate. - Subscribe to SSE: Receive execution results via an event stream until the Session returns to
idle.