multimodelagent
v3.6.0
Published
You can run the example:
Downloads
18
Readme
Example
You can run the example:
import { MultiModelAgent } from "multimodelagent";
import { tool } from "@openai/agents";
import { z } from "zod";
import axios from "axios";
const googleSearch = tool({
name: "google_search",
description: "Search anything using Serper API.",
parameters: z.object({
q: z.string(),
}),
async execute({ q }) {
const response = await axios.post(
"https://google.serper.dev/search",
{ q },
{
headers: {
"X-API-KEY": "YOUR_SERPER_API_KEY",
"Content-Type": "application/json",
},
}
);
return response.data;
},
});
const fetchChunk = tool({
name: "fetch_chunk",
description: "Fetch a small chunk from any webpage.",
parameters: z.object({
url: z.string(),
index: z.number(),
}),
async execute({ url, index }) {
return {
chunk: `Chunk ${index} from ${url}`,
hasMore: index < 2,
};
},
});
const ai = new MultiModelAgent({
apiKey: "YOUR_GROQ_OR_OPENAI_API_KEY",
model: "qwen/qwen3-32b",
baseURL: "https://api.groq.com/openai/v1",
tools: [googleSearch, fetchChunk],
instructions: "You are a helpful AI assistant.",
onToolCall: (name, args) => {
console.log("TOOL CALL =>", name, args);
},
});
const reply = await ai.ask("who are you?");
console.log("AI:", reply);