langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.16k stars 2.05k forks source link

DOC: Create Agent with Gemini #5745

Closed j4kaizen closed 2 months ago

j4kaizen commented 2 months ago

URL

https://v02.api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html

Checklist

Issue with current documentation:

With openAI I use the createOpenAIFunctionsAgent function: const agent = await createOpenAIFunctionsAgent({ llm, tools: tools, prompt: prompt, }); With gemini, which function do I use?

Idea or request for content:

Create Agent

dosubot[bot] commented 2 months ago

To create an agent with Gemini in LangChain, you should use the initializeAgentExecutorWithOptions function. Here is how you can use it:

import { initializeAgentExecutorWithOptions } from 'langchain/src/agents/initialize';
import { YourLLM } from 'path/to/your/llm';
import { YourTool } from 'path/to/your/tool';

const tools = [new YourTool()];
const llm = new YourLLM();

const options = {
  agentType: "zero-shot-react-description", // or any other agent type you need
  agentArgs: { /* your agent arguments */ },
  memory: { /* your memory options if needed */ },
  // other options for AgentExecutor.fromAgentAndTools
};

initializeAgentExecutorWithOptions(tools, llm, options)
  .then(agentExecutor => {
    // Use your agentExecutor here
  })
  .catch(error => {
    console.error("Error initializing agent executor:", error);
  });

Replace YourLLM and YourTool with your actual language model and tool implementations. The options object should be configured based on the type of agent you want to create and any additional arguments or memory options you need [1].

To continue talking to Dosu, mention @dosu.

j4kaizen commented 2 months ago

Function initializeAgentExecutorWithOptions is no Deprecated. url: https://v02.api.js.langchain.com/functions/langchain_agents.initializeAgentExecutorWithOptions.html

jacoblee93 commented 2 months ago

createToolCallingAgent or LangGraph

https://js.langchain.com/v0.2/docs/how_to/agent_executor