Skip to content

Plan before acting

The model writes a plan in the first turn, without tools. From the second turn it carries out the plan.

from alpineagents import Agent, State, loop


@loop(until=State.is_answered, limit=30)
def plan_then_act(agent: Agent, state: State):
    if state.turn == 0:
        agent.think(state, tools=[])
        state.add_notice("Now carry out the plan.")
        return
    agent.think(state)
    if state.wants_tools():
        agent.use_tools(state)
  1. In the first turn, agent.think(state, tools=[]) shows the model no tools, so the reply is text: the plan.
  2. A reply without tool calls makes State.is_answered true. state.add_notice(...) adds a message after it, so the loop continues.
  3. From the second turn, agent.think(state) shows every tool.

Other tool sets per turn

think(state, tools=[...]) accepts any subset of the Agent's tools. For example, only reading tools for the first five turns. Inside the loop body above:

tools = [read_file, list_files] if state.turn < 5 else None
agent.think(state, tools=tools)

tools=None shows all of the Agent's tools. A tool the Agent does not have raises ValueError.