Usage for Agents

Use this page when Codex, Claude Code, OpenClaw, Hermes, or another coding agent is editing code that uses @joytoken/agent-sdk-ts.

What agents should know

TopicInstruction
PackageUse @joytoken/agent-sdk-ts for TypeScript agent loops
ProviderUse createJoyTokenProvider({ apiKey: process.env.JOY_TOKEN_API_KEY })
API keyKeep JOY_TOKEN_API_KEY server-side
ToolsDefine tools with defineTool(); do not execute tools in JoyToken
StateLoad messages before Agent.run() and persist returned messages, steps, and usage
Stop conditionsUse stepCountIs(), maxToolCalls(), and maxCost() together with JoyToken policy and quota

Prompt snippet

agent-instructions.md
Use @joytoken/agent-sdk-ts for JoyToken agent loops.
Create the model provider with createJoyTokenProvider({ apiKey: process.env.JOY_TOKEN_API_KEY }).
Register tools with defineTool({ name, description, parameters, execute }).
Use stopWhen: [stepCountIs(...), maxToolCalls(...)] for bounded runs.
Persist result.messages, result.steps, and result.usage in application storage.
Do not expose JOY_TOKEN_API_KEY in browser code.

Review checklist

CheckWhy it matters
Bounded run loopPrevents infinite model/tool loops
Tool side-effect reviewHigh-risk tool actions need application-level approval
State persistenceAgent SDK returns state, but your app owns storage
Cost guardRuntime stop conditions and JoyToken quota/policy should both exist
Request metadatametadata should include workflow, thread, or step identifiers

Common mistakes

MistakeFix
Calling JoyToken directly inside every toolUse tools for external actions; model calls should go through the Agent model provider
Storing secrets in frontend codeKeep all Agent SDK usage on the server side
Ignoring stoppedByRecord why the run ended for debugging and cost review
Treating maxCost() as the only budget controlAlso configure JoyToken API key quotas, wallet, and policy