Understanding Agenite agents - the central orchestrators of AI interactions.
iterate()
and execute()
Agent
constructor accepts a configuration object with these key properties:
Property | Type | Description | Required |
---|---|---|---|
name | string | Identifies the agent; crucial for multi-agent setups | ✅ |
provider | LLMProvider | The LLM provider that powers the agent | ✅ |
instructions | string | System prompt given to the LLM to guide behavior | ✅ |
tools | Tool[] | Tools the agent can use to accomplish tasks | Optional |
agents | Agent[] | Sub-agents this agent can delegate to | Optional |
stateReducer | StateReducer | Functions that control state updates | Optional |
initialState | Object | Starting state values | Optional |
steps | Record<string, Step> | Custom steps for execution flow | Optional |
startStep | string | Which step to begin with (default: ‘agenite.llm-call’) | Optional |
middlewares | Middleware[] | Functions that intercept execution | Optional |
description | string | Used when this agent is called by others | Optional |
execute()
- Simple runiterate()
- Step-by-step controliterate()
to access the underlying generator:
iterate()
because:
next()
done
becomes trueiterate()
include:
agenite.llm-call
)
agenite.tool-call
)
agenite.tool-result
)
agenite.agent-call
)
agenite.end
)
startStep
(default: ‘agenite.llm-call’)beforeExecute()
to prepare parametersexecute()
which can yield values back to the callerafterExecute()
to process the resultnext
property from the step’s return value to determine the next stepiterate()
loopnext
field, using the updated state
agenite.tool-call
step.
agenite.end
step), the accumulated state is returned as the result:
next()
type
values like middleware.token
and includes arbitrary data properties.
done
, the middleware enhances the final state with additional properties that the caller can access.
agent.iterate()
is called, the step generator is created first, then middlewares are applied in right-to-left order using reduceRight()
. This means the first middleware in the array wraps all others.
middleware.token
) which the iterate loop handles.