Migration does not require an SDK compatibility layer: Hosted Agents exposes standard HTTP + SSE endpoints that you can call with
curl or any HTTP client. The examples below read your API key from the KIMI_API_KEY environment variable.What changes
With a self-built harness, your application code owns every part of the runtime. After migrating, those runtime responsibilities move to the platform:
In short: hand âhow it runsâ to the platform, and keep âwhat task to solveâ in your configuration and business code.
Migration steps
1
Move system prompts, tool definitions, and skills into an Agent configuration
Consolidate the system prompts, tool schemas, and other instructions previously hardcoded in your loop into a persistent Agent configuration object. Create an agent once and reference it by ID across sessions; each update creates a new immutable version.Here is how components from your loop map to Hosted Agents:
- System prompt â the agentâs
systemfield. - Business tools executed on your client â declare them as custom tools so your client continues executing them; to let the platform connect directly to third-party services, use MCP.
- Hand-written utility tools (search, file I/O, shell commands) â agents get built-in cloud sandbox tools (file read/write, code execution, web search, and more) by defaultâno declaration neededâso you can delete your own implementations.
- Structured domain playbooks (prompts + scripts + templates) â package and attach them as skills.
2
Delete your custom agent loop and message history storage
In this step, you can remove the following boilerplate harness components entirely:
- The main orchestration loop (âcall model â parse tool calls â execute tools â append results â call model againâ).
- Assembling and truncating message history, and maintaining persistent message storage.
- Fallback logic for crash recovery, stream reconnection, and timeout retries.
3
Switch to creating a session, subscribing to the event stream, and sending events
Replace single-turn Model Inference API calls with a three-step flow: create a session, subscribe to its event stream, and send events. Below, For session creation, status transitions, and lifecycle details, see Create a Session.
AGENT_ID is the id returned in Step 1, SESSION_ID is the id returned when creating the session, and ENVIRONMENT_ID is the id returned when you create an execution environment:What you do not need to migrate
The platform provides the capabilities below out of the box, so you do not need to rebuild them in your system:- Persistent session history: Event history is persisted server-side and can be fetched in full at any time without maintaining your own message database.
- Disconnect and failure recovery: Event streams resume from a cursor after network drops, and after a platform failure, execution automatically recovers and resumes from where it left off.
- Timeouts and retries: Execution-layer retries, scheduling, and context compaction are managed by the platformâyour client only needs to handle HTTP error codes for its own requests.
Next steps
Migrate agent configuration
Consolidate system prompts and tool definitions into a versioned Agent configuration.
Start a managed session
Create sessions and send events in place of a self-built agent loop.
Inspect event history
Subscribe to events, resume from cursors, and review all event types.