defineContexts
Define contexts and steps for multi-step conversation workflows. Contexts allow an agent to guide the caller through a structured sequence of interactions — such as gathering information, verifying identity, and then performing an action.
Called with no argument, it returns the agent’s ContextBuilder,
creating it on first use, so calling it again adds to the same workflow. Passing a
ContextBuilder replaces the current one and returns it. Passing a plain object uses
that object as the contexts, rendered as it is, and returns the agent.
The contexts render inside the AI prompt, as ai.prompt.contexts.
Contexts can coexist with traditional prompts. The only restriction is that POM sections and raw text cannot be mixed in the main prompt.
Parameters
contexts
A ContextBuilder to use in place of the current one, or the contexts as a plain
object. Omit it to get the current builder. Throws a TypeError for a value that
is neither.
Returns
ContextBuilder — The active ContextBuilder for further
configuration, or AgentBase (this) when given a plain object.
Examples
Fluent ContextBuilder
addStep() is a method on Context, not on Step. Since Step methods like
setValidSteps() return the Step (not the parent Context), you must keep a
reference to the Context and call addStep() on it for each new step.