SimpleLLMFunc agents are stateless by default — they don’t store conversation history internally. You pass history in, you get updated history back. This makes state management explicit and testable.
import asynciofrom SimpleLLMFunc import OpenAICompatible, llm_chatfrom SimpleLLMFunc.hooks import is_response_yield, is_event_yieldmodels = OpenAICompatible.load_from_json_file("provider.json")llm = models["openrouter"]["openai/gpt-4o"]@llm_chat(llm_interface=llm, stream=True)async def chat(message: str, history: list | None = None): """ You are a concise, helpful assistant. Remember context from earlier in the conversation. """ pass
The parameter named history (or chat_history) is special — the framework uses it to carry conversation state between turns.
async def main(): history = [] # Turn 1 print("User: What is Python?") print("Assistant: ", end="") async for output in chat("What is Python?", history): if is_response_yield(output): print(output.response, end="") history = output.messages print("\n") # Turn 2 — the agent remembers turn 1 print("User: What are its main features?") print("Assistant: ", end="") async for output in chat("What are its main features?", history): if is_response_yield(output): print(output.response, end="") history = output.messages print()asyncio.run(main())
Each output.messages contains the full updated conversation. Pass it back for the next turn.