What Logic is for
The Logic tab lets you write Python code that runs at key moments in the agent’s cycle. From here you can calculate values and prepare variables that you’ll later use in the agent’s Initial Message or Instructions.
The two code blocks
Initial Code
Initial Code
Runs only once, when the agent activates for the first time.Ideal for:In this example,
- Calculating today’s date and storing it in the context.
- Preparing variables derived from the campaign file.
- Initializing counters or status flags.
context["agent_name"] = "Ana" sets the name the agent introduces itself with. That variable is automatically injected into the prompt — it’s the same {agent_name} you can use in the Initial Message or Instructions (see Identity) — so throughout the conversation the agent is named “Ana.”Pre-Instructions Code
Pre-Instructions Code
Runs before every interaction with the LLM — that is, on every conversation turn.Ideal for:
- Updating counters or flags based on what happened on the previous turn.
- Recalculating derived variables as the conversation progresses.
- Logging metrics per turn.
The context dictionary
All of the agent’s values — campaign variables, conversation state, dynamic configuration — live in the context dictionary. You can read and write freely, and any variable you store there becomes available to use with {variable} in the agent’s Initial Message and Instructions.
Full example
elapsed_turns available in the context, you can reference it directly in the agent’s Instructions, for example: