Skip to content

Commit 9346422

Browse files
ryx2claude
andauthored
docs: Add message_history parameter documentation for CLI methods (#2695)
Co-authored-by: Claude <[email protected]>
1 parent 08bd090 commit 9346422

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/cli.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,25 @@ async def main():
108108
```
109109

110110
_(You'll need to add `asyncio.run(main())` to run `main`)_
111+
112+
### Message History
113+
114+
Both `Agent.to_cli()` and `Agent.to_cli_sync()` support a `message_history` parameter, allowing you to continue an existing conversation or provide conversation context:
115+
116+
```python {title="agent_with_history.py" test="skip"}
117+
from pydantic_ai import Agent
118+
from pydantic_ai.messages import ModelMessage, ModelRequest, ModelResponse, UserPromptPart, TextPart
119+
120+
agent = Agent('openai:gpt-4.1')
121+
122+
# Create some conversation history
123+
message_history: list[ModelMessage] = [
124+
ModelRequest([UserPromptPart(content='What is 2+2?')]),
125+
ModelResponse([TextPart(content='2+2 equals 4.')])
126+
]
127+
128+
# Start CLI with existing conversation context
129+
agent.to_cli_sync(message_history=message_history)
130+
```
131+
132+
The CLI will start with the provided conversation history, allowing the agent to refer back to previous exchanges and maintain context throughout the session.

0 commit comments

Comments
 (0)