Skip to content

Create Task State

client.states.create(StateCreateParams { agent_id, state, task_id } body, RequestOptionsoptions?): State { id, agent_id, created_at, 3 more }
POST/states

Create Task State

ParametersExpand Collapse
body: StateCreateParams { agent_id, state, task_id }
agent_id: string
state: Record<string, unknown>
task_id: string
ReturnsExpand Collapse
State { id, agent_id, created_at, 3 more }

Represents a state in the agent system. A state is associated uniquely with a task and an agent.

This entity is used to store states in MongoDB, with each state associated with a specific task and agent. The combination of task_id and agent_id is globally unique.

The state is a dictionary of arbitrary data.

id: string

The task state’s unique id

agent_id: string
created_at: string

The timestamp when the state was created

formatdate-time
state: Record<string, unknown>
task_id: string
updated_at?: string | null

The timestamp when the state was last updated

formatdate-time

Create Task State

import Agentex from 'agentex';

const client = new Agentex({
  apiKey: process.env['AGENTEX_SDK_API_KEY'], // This is the default and can be omitted
});

const state = await client.states.create({
  agent_id: 'agent_id',
  state: { foo: 'bar' },
  task_id: 'task_id',
});

console.log(state.id);
{
  "id": "id",
  "agent_id": "agent_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": {
    "foo": "bar"
  },
  "task_id": "task_id",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
Returns Examples
{
  "id": "id",
  "agent_id": "agent_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "state": {
    "foo": "bar"
  },
  "task_id": "task_id",
  "updated_at": "2019-12-27T18:11:19.117Z"
}