Execution Model
Agents execute by implementing run and unwind functions.
Execution Flow
Circuit infrastructure sends either a
runor aunwindcommand to your agentSDK receives the request and creates an
AgentContextSDK calls your
runfunction with theAgentContextas the agent variableYour code executes using SDK methods
SDK returns execution results to Circuit
(Manual Mode) If your agent operates in manual mode, all transactions will be submitted to the user to approve in the Circuit UI.
Modes
There are 2 modes that are available for agents to operate in: auto and manual. The agent developer will decide which modes are available to the user via the allowedExecutionModes property in the agent's .circuit.toml file. The selected executionMode will be available in the agent context.
auto- Transactions are executed automaticallymanual- Transactions will be submitted for the user to approve on the circuit UI.
From the agent's perspective, there is no difference in submitting a request to either execute automatically, or suggest a transaction. Circuit's API will correctly execute a transaction or log a suggestion based on the session's selected execution mode. The only difference for the agent will be in the response data, which will include the below properties:
suggested: boolsuggestionId: int
Important: All suggested transactions will be soft deleted at the beginning of all agent
runexecutions automatically. If you need a shorter expiry time than the sleep interval defined in the .circuit.tomlfile, you can set that when submitting the transaction with theexpiresAtfield.
Asset Allocation
Every agent execution starts with agent.currentPositions - the assets allocated to this session. This is the foundation for agent decision-making:
See the Agent Context session for more details on what is available in the agent's execution context
Check what assets are available
Decide what actions to take based on holdings
Execute trades, swaps, or other operations
General pattern you should follow:
Read
currentPositionsto understand current holdingsApply strategy logic to determine desired state
Use SDK methods (Swidge, platforms) to reach desired state
Run Function
The run function is called periodically for all active sessions based on the defined defaultSleepIntervalMinutes in .circuit.toml.
Unwind Function
The unwind function is called when a user unwinds the agent. It receives a list of positions to unwind, which may be a subset of the agent’s current positions.
Execution Interval
Set defaultSleepIntervalMinutes in .circuit.toml:
This determines how often run is called. The interval starts after the previous run completes.
Last updated