-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add agents, an example on how to use the agents
- Loading branch information
1 parent
f5dc916
commit d85bc1f
Showing
9 changed files
with
2,525 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@neuron.js/examples-weatheragent", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "tsx src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@neuron.js/core": "workspace:*", | ||
"axios": "^1.7.9", | ||
"dotenv": "^16.4.7" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.10.1", | ||
"tsx": "^4.19.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Agent, Tool } from '@neuron.js/core'; | ||
import 'dotenv/config' | ||
|
||
const weatherTool = new Tool( | ||
'weather_gov_query', | ||
'Fetches real-time weather data from an weather.gov.', | ||
{ | ||
properties: { | ||
latitude: { | ||
type: 'string', | ||
description: 'latitude of the location where weather data is required', | ||
required: true | ||
}, | ||
longitude: { | ||
type: 'string', | ||
description: 'latitude of the location where weather data is required', | ||
required: true | ||
}, | ||
locationName: { | ||
type: 'string', | ||
description: 'name of the location where weather data is required', | ||
required: true | ||
} | ||
}, | ||
}, | ||
async (inputs, secrets) => { | ||
try { | ||
const response = await fetch( | ||
`https://api.weather.gov/points/${inputs.latitude},${inputs.longitude}` | ||
); | ||
const data = await response.json(); | ||
const forecastResponse = await fetch(data.properties.forecast); | ||
const forecastData = await forecastResponse.json(); | ||
return `Weather forecast in ${inputs.locationName} is ${forecastData.properties.periods[0].detailedForecast}`; | ||
} catch (error) { | ||
console.error('Error:', error); | ||
throw error; | ||
} | ||
} | ||
) | ||
|
||
|
||
const WeatherAgent = new Agent( | ||
'WeatherAgent', | ||
{ | ||
persona: 'You are a cheerful and approachable virtual assistant dedicated to delivering accurate, concise, and engaging weather updates. Your tone is warm, lively, and always focused on making weather information easy to understand and fun to receive.', | ||
goal: 'Provide the current weather for a specified location as soon as the city or location details are provided. Your response should be both informative and conversational, ensuring clarity and usefulness for the user.', | ||
secrets: { | ||
OPEN_WEATHER_API_KEY: process.env.OPEN_WEATHER_API_KEY || '', | ||
OPENAI_API_KEY: process.env.OPENAI_API_KEY || '' | ||
} | ||
} | ||
) | ||
|
||
WeatherAgent.registerTool(weatherTool) | ||
|
||
const result = await WeatherAgent.execute("I'm travelling to Tahoe, what is the weather there?") | ||
console.log("RESULT:", result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './agent'; | ||
export * from './tool'; | ||
export * from './llm'; | ||
export * from './errors'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.