@ziggs-ai/agent-sdk
v0.1.3
Published
Agent framework SDK for building autonomous agents on the Ziggs platform
Readme
@ziggs-ai/agent-sdk
What it is: A small JavaScript framework for building autonomous agents that run on the Ziggs platform. You describe behavior as a workflow (states, prompts, actions, transitions), wire tools, and the SDK handles LLM calls, context, tasks, and optional WebSocket connectivity to Ziggs.
It is not a generic chat wrapper: the core idea is a lightweight state machine (AgentMachine) that walks your definition, runs runTurn for "thinking" steps (prompt + structured actions), and updates context from events and transitions so routing stays explicit and predictable.
Mental model
| Piece | Role |
|--------|------|
| defineAgent / workflow | Declarative agent: initial, states, optional id, description, specialization, merged tools / services. |
| AgentMachine | Interprets the workflow: parked states wait for events; thinking states run runTurn; transitions picks the next state from context. |
| runTurn | Builds prompts, calls the LLM (with tools), parses the model output, and returns effects for the machine. |
| ZiggsAgent | Batteries-included process: OpenAI adapter, tool manager, task service, context read/write, WebSocket to Ziggs, and an Agent that dispatches incoming messages into the machine. |
| Agent | Orchestrates message handling, machine lifecycle, and integration with platform APIs (without requiring you to use WebSockets if you construct it yourself). |
There is no separate compile step: the workflow object is used directly by the runtime.
Workflow DSL (states)
States are plain objects on workflow.states. Every state uses one unified concept:
transitions— an array of{ to, when }rules evaluated in order. The first rule whosewhen(ctx)returns true (or has nowhen) determines the next state. Supports a plain string shorthand:'stateName'is equivalent to{ to: 'stateName' }.
Two kinds of state:
Parked / waiting: Has only
transitions. The machine stops here and waits for the next event. When an event arrives it is classified into context flags (approval,rejection,subtaskResult, etc.) andtransitionsis evaluated to route forward.Thinking: Has
prompt,actions, andtransitions. The machine runs an LLM turn viarunTurn, applies the result into context flags (messageSent,toolResults,taskCompleted, etc.), then evaluatestransitionsto route forward.
Both kinds use the same transitions array and the same context shape — the only difference is what filled the context before evaluation.
Context flags available in transitions:
| Set by incoming events (parked states) | Set by LLM turn results (thinking states) |
|---------------------------------------|------------------------------------------|
| approval, rejection | messageSent, activeWait |
| taskAssignment, subtaskResult | proposal, delegatedTask |
| subtaskFailed, incomingMessage | taskCompleted, taskFailed |
| | toolResults, lastError, respondedProposal |
The wait action is built-in: defineAgent automatically injects it into every thinking state that doesn't define one, and appends a { to: initial, when: ctx => ctx.activeWait } transition if none exists.
How you usually run an agent
defineAgent({ ... })→ options object includingworkflow.- Pass
openaiKey,operatorKey(Ziggs operator token),agentId,wsUrl, etc., andnew ZiggsAgent(config)(orcreateAgent(config)). connect()to open the WebSocket; the SDK routes platform messages intohandleMessage.
Examples in the repo: examples/agents/*.js (e.g. coffee, expense, delivery agents).
Main exports (entry: src/index.js)
ZiggsAgent,createAgent,defineAgentAgent,AgentMachine,runTurn- Prompt / tools:
PromptBuilder,ToolManager,defineTool - Task tools:
taskMakeTaskTool,taskUpdateTaskTool,taskRespondProposalTool,taskMakeSubTasksTool,taskUpdatePlanStepTool,TASK_PROTOCOL_TOOLS - Adapters / utils:
OpenAIAdapter, JSON helpers, formatters - Re-exported from
@ziggs-ai/api-client:WebSocketClient,ContextReader,ContextWriter, URL helpers, etc.
Package export: "." → src/index.js (see package.json).
Requirements
- Node ≥ 18
- Env:
OPENAI_API_KEY(and optionallyOPENAI_MODEL) fordefineAgentdefaults; ZiggsZIGGS_OPERATOR_KEY(operator token, scopeagents:impersonate) for platform features.
License
MIT (see package metadata).
