OpenAIMultiFunctionsAgent#

class langchain.agents.openai_functions_multi_agent.base.OpenAIMultiFunctionsAgent[source]#

Bases: BaseMultiActionAgent

Deprecated since version 0.1.0: Use create_openai_tools_agent() instead.

Agent driven by OpenAIs function powered API.

Parameters:
  • llm – This should be an instance of ChatOpenAI, specifically a model that supports using functions.

  • tools – The tools this agent has access to.

  • prompt – The prompt for this agent, should support agent_scratchpad as one of the variables. For an easy way to construct this prompt, use OpenAIMultiFunctionsAgent.create_prompt(…)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param llm: BaseLanguageModel [Required]#
param prompt: BasePromptTemplate [Required]#
param tools: Sequence[BaseTool] [Required]#
async aplan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None = None, **kwargs: Any) β†’ List[AgentAction] | AgentFinish[source]#

Async given input, decided what to do.

Parameters:
  • intermediate_steps (List[Tuple[AgentAction, str]]) – Steps the LLM has taken to date, along with observations.

  • callbacks (list[BaseCallbackHandler] | BaseCallbackManager | None) – Callbacks to use. Default is None.

  • **kwargs (Any) – User inputs.

Returns:

Action specifying what tool to use.

Return type:

List[AgentAction] | AgentFinish

classmethod create_prompt(system_message: SystemMessage | None = SystemMessage(content='You are a helpful AI assistant.', additional_kwargs={}, response_metadata={}), extra_prompt_messages: List[BaseMessagePromptTemplate] | None = None) β†’ BasePromptTemplate[source]#

Create prompt for this agent.

Parameters:
  • system_message (SystemMessage | None) – Message to use as the system message that will be the first in the prompt.

  • extra_prompt_messages (List[BaseMessagePromptTemplate] | None) – Prompt messages that will be placed between the system message and the new human input. Default is None.

Returns:

A prompt template to pass into this agent.

Return type:

BasePromptTemplate

classmethod from_llm_and_tools(llm: BaseLanguageModel, tools: Sequence[BaseTool], callback_manager: BaseCallbackManager | None = None, extra_prompt_messages: List[BaseMessagePromptTemplate] | None = None, system_message: SystemMessage | None = SystemMessage(content='You are a helpful AI assistant.', additional_kwargs={}, response_metadata={}), **kwargs: Any) β†’ BaseMultiActionAgent[source]#

Construct an agent from an LLM and tools.

Parameters:
  • llm (BaseLanguageModel) – The language model to use.

  • tools (Sequence[BaseTool]) – A list of tools to use.

  • callback_manager (BaseCallbackManager | None) – The callback manager to use. Default is None.

  • extra_prompt_messages (List[BaseMessagePromptTemplate] | None) – Extra prompt messages to use. Default is None.

  • system_message (SystemMessage | None) – The system message to use. Default is a default system message.

  • kwargs (Any) – Additional arguments.

Return type:

BaseMultiActionAgent

get_allowed_tools() β†’ List[str][source]#

Get allowed tools.

Return type:

List[str]

plan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None = None, **kwargs: Any) β†’ List[AgentAction] | AgentFinish[source]#

Given input, decided what to do.

Parameters:
  • intermediate_steps (List[Tuple[AgentAction, str]]) – Steps the LLM has taken to date, along with observations.

  • callbacks (list[BaseCallbackHandler] | BaseCallbackManager | None) – Callbacks to use. Default is None.

  • **kwargs (Any) – User inputs.

Returns:

Action specifying what tool to use.

Return type:

List[AgentAction] | AgentFinish

return_stopped_response(early_stopping_method: str, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any) β†’ AgentFinish#

Return response when agent has been stopped due to max iterations.

Parameters:
  • early_stopping_method (str) – Method to use for early stopping.

  • intermediate_steps (List[Tuple[AgentAction, str]]) – Steps the LLM has taken to date, along with observations.

  • **kwargs (Any) – User inputs.

Returns:

Agent finish object.

Return type:

AgentFinish

Raises:

ValueError – If early_stopping_method is not supported.

save(file_path: Path | str) β†’ None#

Save the agent.

Parameters:

file_path (Path | str) – Path to file to save the agent to.

Raises:
  • NotImplementedError – If agent does not support saving.

  • ValueError – If file_path is not json or yaml.

Return type:

None

Example: .. code-block:: python

# If working with agent executor agent.agent.save(file_path=”path/agent.yaml”)

tool_run_logging_kwargs() β†’ Dict#

Return logging kwargs for tool run.

Return type:

Dict

property functions: List[dict]#

Get the functions for the agent.

property input_keys: List[str]#

Get input keys. Input refers to user input here.

property return_values: List[str]#

Return values of the agent.