ahvn.agent.base module¶
- class ahvn.agent.base.BaseAgentSpec(tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]¶
基类:
ABC- abstractmethod encode(**inputs)[源代码]¶
Convert input arguments into Messages for the agent.
- 参数:
**inputs -- Arbitrary input arguments.
- 返回:
The encoded messages for the agent.
- 返回类型:
Messages
- step(messages, include=None)[源代码]¶
Execute a single LLM call with streaming.
- 参数:
messages (
Union[str,Dict[str,Any],Any,List[Union[str,Dict[str,Any],Any]]]) -- Current conversation messages.include (
Optional[List[Literal['text','think','tool_calls','content','message','structured','tool_messages','tool_results','delta_messages','messages']]]) -- Fields to include in the stream chunks.
- 生成器:
Stream chunks from the LLM.
- 返回类型:
- user_proxy(messages, delta_messages, finish_state=None)[源代码]¶
Add a user proxy message to prompt the agent to continue.
This is called when the agent is not done after a step, to encourage it to keep going.
- 参数:
- 返回:
A list of messages to append.
- 返回类型:
Messages
- stream(messages, include=None)[源代码]¶
Stream the agent execution, yielding chunks as they are generated.
This is the core streaming interface. Each chunk contains: - Standard LLM fields: text, think, tool_calls, tool_messages, etc. - Agent control fields: step, done, finish_state, messages
- 参数:
messages (
Union[str,Dict[str,Any],Any,List[Union[str,Dict[str,Any],Any]]]) -- Initial messages to start the agent.include (
Optional[List[Literal['text','think','tool_calls','content','message','structured','tool_messages','tool_results','delta_messages','messages']]]) -- Fields to include in the stream. Defaults to common fields.
- 生成器:
AgentStreamChunk -- Stream chunks with LLM output and agent state.
- 返回类型:
- run(messages, include=None)[源代码]¶
Run the agent to completion, collecting all stream output.
This is a convenience wrapper around stream() that blocks until completion.
- 参数:
messages (
Union[str,Dict[str,Any],Any,List[Union[str,Dict[str,Any],Any]]]) -- Initial messages to start the agent.include (
Optional[List[Literal['text','think','tool_calls','content','message','structured','tool_messages','tool_results','delta_messages','messages']]]) -- Fields to include (passed to stream).
- 返回类型:
Tuple[Union[str,Dict[str,Any],Any,List[Union[str,Dict[str,Any],Any]]],Dict[str,Any]]- 返回:
Tuple of (final_messages, finish_state).
- class ahvn.agent.base.BasePromptAgentSpec(prompt, tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]¶
-
- 参数:
prompt (PromptUKFT)
llm_args (Dict | None)
max_steps (int | None)
- __init__(prompt, tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]¶
- 参数:
prompt (PromptUKFT)
llm_args (Dict | None)
max_steps (int | None)