Skip to main content

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. Logic tab with Initial Code and Pre-Instructions Code

The two code blocks

Runs only once, when the agent activates for the first time.Ideal for:
  • Calculating today’s date and storing it in the context.
  • Preparing variables derived from the campaign file.
  • Initializing counters or status flags.
In this example, 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.”
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

With elapsed_turns available in the context, you can reference it directly in the agent’s Instructions, for example:
To verify your code works as expected, use Open conversation — you can load test variables and see in real time how the agent behaves with the values you calculated in Logic.