langchain.agents.openai_functions_multi_agent.base.OpenAIMultiFunctionsAgent

class langchain.agents.openai_functions_multi_agent.base.OpenAIMultiFunctionsAgent(*, llm: BaseLanguageModel, tools: Sequence[BaseTool], prompt: BasePromptTemplate)[source]

Bases: BaseMultiActionAgent

An 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 if the input data cannot be parsed to form a valid model.

param llm: langchain.schema.language_model.BaseLanguageModel [Required]
param prompt: langchain.schema.prompt_template.BasePromptTemplate [Required]
param tools: Sequence[langchain.tools.base.BaseTool] [Required]
async aplan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) Union[List[AgentAction], AgentFinish][source]

Given input, decided what to do.

Parameters
  • intermediate_steps – Steps the LLM has taken to date, along with observations

  • **kwargs – User inputs.

Returns

Action specifying what tool to use.

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

Create prompt for this agent.

Parameters
  • system_message – Message to use as the system message that will be the first in the prompt.

  • extra_prompt_messages – Prompt messages that will be placed between the system message and the new human input.

Returns

A prompt template to pass into this agent.

dict(**kwargs: Any) Dict

Return dictionary representation of agent.

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

Construct an agent from an LLM and tools.

get_allowed_tools() List[str][source]

Get allowed tools.

plan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) Union[List[AgentAction], AgentFinish][source]

Given input, decided what to do.

Parameters
  • intermediate_steps – Steps the LLM has taken to date, along with observations

  • **kwargs – User inputs.

Returns

Action specifying what tool to use.

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.

save(file_path: Union[Path, str]) None

Save the agent.

Parameters

file_path – Path to file to save the agent to.

Example: .. code-block:: python

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

tool_run_logging_kwargs() Dict
validator validate_llm  »  all fields[source]
validator validate_prompt  »  all fields[source]
property functions: List[dict]
property input_keys: List[str]

Get input keys. Input refers to user input here.

property return_values: List[str]

Return values of the agent.