voicemate.agent.graph¶
The LangGraph agent: recall → agent ⇄ tools.
recallembeds the user message, loads matching facts, past exchanges and research, and builds the per-turn context block (about 30-50 ms, so no speculation is needed).The system prompt is static and the context is attached only to the newest user message, so Ollama can reuse its KV cache for the long, tool-laden prompt prefix (see prompts.py).
agentcalls the chat model with all tools bound. Aftermax_tool_roundstool rounds the tools are unbound so the model has to answer.toolsruns the requested tools; exceptions become error messages the model can read.
Conversation history is persisted per thread_id by the checkpointer. Events for the UI
are sent through the emit callback in config["configurable"].
Attributes¶
Classes¶
Graph state. |
Functions¶
|
The Ollama chat model with thinking disabled (latency matters more for voice). |
|
The last |
|
Copy of |
|
Prefill the static prompt prefix so the first real turn hits Ollama's KV cache. |
|
Compile the agent graph. |
Module Contents¶
- voicemate.agent.graph.HISTORY_MESSAGES: int = 24¶
- voicemate.agent.graph.ANSWER_NUDGE: str = "You have the tool results now: answer the user's question in full."¶
- voicemate.agent.graph.NO_MORE_TOOLS: str = 'Tool budget for this turn is used up: answer now with what you have.'¶
- class voicemate.agent.graph.AgentState[source]¶
Bases:
TypedDictGraph state.
- Variables:
messages – Conversation history (appended through the
add_messagesreducer).lang – Reply language of the current turn.
context – Per-turn context block (time, language, memories) for the newest message.
tool_rounds – Tool rounds used in the current turn.
Initialize self. See help(type(self)) for accurate signature.
- messages: Annotated[list[langchain_core.messages.AnyMessage], langgraph.graph.message.add_messages]¶
- lang: str¶
- context: str¶
- tool_rounds: int¶
- voicemate.agent.graph.make_chat_model(config: voicemate.config.LLMConfig, model: str | None = None) langchain_core.language_models.BaseChatModel[source]¶
The Ollama chat model with thinking disabled (latency matters more for voice).
- Parameters:
config – LLM settings.
model – Model tag; defaults to the preferred profile’s model.
- voicemate.agent.graph.recent_history(messages: collections.abc.Sequence[langchain_core.messages.AnyMessage], limit: int = HISTORY_MESSAGES) list[source]¶
The last
limitmessages, starting at a user message.Starting at a user message keeps tool results together with the call that produced them.
- voicemate.agent.graph.with_context(messages: list[langchain_core.messages.AnyMessage], context: str) list[langchain_core.messages.AnyMessage][source]¶
Copy of
messageswhose newest user message is prefixed withcontext.
- async voicemate.agent.graph.warm_up(llm: langchain_core.language_models.BaseChatModel, tools: list[langchain_core.tools.BaseTool], config: voicemate.config.Config) None[source]¶
Prefill the static prompt prefix so the first real turn hits Ollama’s KV cache.
- voicemate.agent.graph.build_graph(llm: langchain_core.language_models.BaseChatModel, tools: list[langchain_core.tools.BaseTool], config: voicemate.config.Config, memory: voicemate.memory.store.MemoryStore | None = None, checkpointer: Any = None, now: collections.abc.Callable[[], datetime.datetime] = lambda : ...) Any[source]¶
Compile the agent graph.
- Parameters:
llm – Chat model supporting tool calling.
tools – Tools to bind.
config – Application config.
memory – Long-term memory used by the recall node (skipped when None).
checkpointer – LangGraph checkpointer for per-thread history.
now – Clock for the turn context.
- Returns:
The compiled graph.