ahvn.agent.base module

class ahvn.agent.base.BaseAgentSpec(tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]

基类:ABC

参数:
__init__(tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]
参数:
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.

返回类型:

Generator[Dict[str, Any], None, None]

abstractmethod is_done(messages, delta_messages)[源代码]
返回类型:

Tuple[bool, Dict[str, Any]]

参数:
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

abstractmethod decode(messages, finish_state=None)[源代码]
返回类型:

Any

参数:
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.

返回类型:

Generator[Dict[str, Any], None, None]

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).

__call__(**inputs)[源代码]

Convenience method to encode, run, and decode in one call.

参数:

**inputs -- Input arguments passed to encode().

返回类型:

Any

返回:

Decoded output from the agent.

class ahvn.agent.base.BasePromptAgentSpec(prompt, tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]

基类:BaseAgentSpec

参数:
__init__(prompt, tools=None, llm_args=None, max_steps=None, **kwargs)[源代码]
参数:
encode(**inputs)[源代码]

Convert input arguments into Messages for the agent.

参数:

**inputs -- Arbitrary input arguments.

返回:

The encoded messages for the agent.

返回类型:

Messages