LangChain agent
LangChain-based agent implementation for coshop.
Extends :class:~coshop.utils.agent.Agent with a LangChain ReAct executor,
token/runtime tracking, and helper methods for copying agent state to temporary
agents (used during final item ranking).
LangchainAgent(actions=[], model_name='gpt-5-nano', model_kwargs={'reasoning_effort': 'minimal'}, max_react_steps=25, verbosity=0, **kwargs)
Bases: Agent
Base class for agents that use LangChain models. Provides common LangChain functionality.
Initialize the LangChain agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
List[StructuredTool]
|
List of tools/actions available to the agent (must be set before calling this) |
[]
|
model_name
|
str
|
Name of the model to use |
'gpt-5-nano'
|
model_kwargs
|
dict
|
Additional keyword arguments for the model |
{'reasoning_effort': 'minimal'}
|
max_react_steps
|
int
|
Maximum number of ReAct steps |
25
|
verbosity
|
Literal[0, 1, 2]
|
Whether to print verbose output |
0
|
**kwargs
|
Additional arguments passed to parent class |
{}
|
cumulative_token_breakdown
property
Cumulative token usage across every LLM call this agent makes — conversation turns, final-prediction / report calls, and summarizer / compression calls. Counted at the model layer (LangChainModel) and read through here; prediction/report agents share the executor's counter, so their usage is included automatically. Keys: "input", "input_cached", "output", "reasoning".
insert_message(role, content, persist_state=True)
Insert a message into the conversation history without making an LLM call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
str
|
Message role ("system", "user", "assistant", or "tool") |
required |
content
|
str
|
Message content |
required |
persist_state
|
bool
|
If True, appends the message to the graph state |
True
|
reset()
Reset the agent to its initial state.
parse_langchain_response_to_actions(raw)
Parse the raw response from a LangChain model into a list of Action objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
List[Any]
|
List of BaseMessage objects from LangChain |
required |
Returns:
| Type | Description |
|---|---|
List[Action]
|
List of Action objects with content, tool_calls, and status |