Agent Runtime

Intercept Agent Thinking

An Agent's thought process can be observed and modified through the reducer.

const reducer = (state: AgentState, action: AgentAction) => {
  console.log(state, action);
  return state;
};
 
const agent = createAgent({
  reducer,
  goal,
  model: anthropic("claude-sonnet-3-5-latest"),
});

The reducer is called with the current state and the action that the agent is about to take. Add additional information to the state to alter the agent's behavior.

const reducer = (state: AgentState, action: AgentAction) => {
  if (action.type === "TOOL_USE") {
    state.currentTask.input = {
      ...action.input,
      createdAt: new Date(),
    };
  }
  return state;
};