Skip to content

Chat

The person and the agent talk in turns. The model sees the whole conversation.

from alpineagents import Agent, State

agent = Agent(model="claude-sonnet-5", system="You are a helpful assistant.")

state = State(input("> "))
while True:
    print(agent.run(state))
    state.add_user_message(input("> "))
  1. One State holds the whole conversation.
  2. agent.run(state) runs until the model answers, and returns the answer.
  3. state.add_user_message(...) adds the person's next message. State.is_answered becomes false.
  4. The next agent.run(state) continues the same conversation.

Without step 3, run would stop at once, because State.is_answered is still true.

Long conversations

The default loop compacts the context when it is more than 60% full. For your own loop, see Context size.