2024-06-02 08:06:45 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
import 'dotenv/config'
|
|
|
|
|
2024-08-04 06:32:30 +00:00
|
|
|
import { createLangChainTools } from '@agentic/langchain'
|
2024-08-04 10:34:47 +00:00
|
|
|
import { WeatherClient } from '@agentic/stdlib'
|
2024-06-02 08:06:45 +00:00
|
|
|
import { ChatPromptTemplate } from '@langchain/core/prompts'
|
|
|
|
import { ChatOpenAI } from '@langchain/openai'
|
|
|
|
import { AgentExecutor, createToolCallingAgent } from 'langchain/agents'
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const weather = new WeatherClient()
|
|
|
|
|
|
|
|
const tools = createLangChainTools(weather)
|
|
|
|
const agent = createToolCallingAgent({
|
2024-08-04 10:55:47 +00:00
|
|
|
llm: new ChatOpenAI({ model: 'gpt-4o-mini', temperature: 0 }),
|
2024-06-02 08:06:45 +00:00
|
|
|
tools,
|
|
|
|
prompt: ChatPromptTemplate.fromMessages([
|
2024-06-02 22:30:39 +00:00
|
|
|
['system', 'You are a helpful assistant. Be as concise as possible.'],
|
2024-06-02 08:06:45 +00:00
|
|
|
['placeholder', '{chat_history}'],
|
|
|
|
['human', '{input}'],
|
|
|
|
['placeholder', '{agent_scratchpad}']
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
const agentExecutor = new AgentExecutor({
|
|
|
|
agent,
|
2024-06-02 08:16:23 +00:00
|
|
|
tools
|
|
|
|
// verbose: true
|
2024-06-02 08:06:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const result = await agentExecutor.invoke({
|
|
|
|
input: 'What is the weather in San Francisco?'
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(result.output)
|
|
|
|
}
|
|
|
|
|
|
|
|
await main()
|