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("> "))
- One State holds the whole conversation.
agent.run(state)runs until the model answers, and returns the answer.state.add_user_message(...)adds the person's next message.State.is_answeredbecomes false.- 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.