-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement forceFinalAnswer Logic and Update Test Cases (#22)
### PR Description: This PR introduces the `forceFinalAnswer` logic, which triggers a final answer from the AI agent when approaching the maximum iteration limit. This feature ensures that the agent utilizes all gathered information to provide a decisive response before the session expires. Additionally, the PR includes several updates and fixes: - **Fix in Self-Question Logic**: Revised the handling of `self_question` actions to ensure they are passed back correctly to the LLM for a coherent follow-up. - **Gemini Test Cases**: Added new test cases to the `sports_news` team scenarios, enhancing our test coverage. - **Snapshot Updates**: Updated snapshots to reflect the new `forceFinalAnswer` logic, ensuring our tests remain accurate and reliable.
- Loading branch information
Showing
13 changed files
with
27,508 additions
and
4 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
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,106 @@ | ||
import { Agent, Task, Team } from 'agenticjs'; | ||
|
||
import { TavilySearchResults } from '@langchain/community/tools/tavily_search'; | ||
|
||
// Define tools | ||
const searchInternet = new TavilySearchResults({ | ||
maxResults: 3, | ||
// apiKey: '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', | ||
apiKey: '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', | ||
}); | ||
|
||
// Define agents with exact roles, goals, and backgrounds from Python example | ||
const citySelectorAgent = new Agent({ | ||
name: 'Peter Atlas', | ||
role: 'City Selection Expert', | ||
goal: 'Select the best city based on weather, season, and prices', | ||
background: 'An expert in analyzing travel data to pick ideal destinations', | ||
type: 'ReactChampionAgent', | ||
tools: [searchInternet], | ||
maxIterations: 20, | ||
llmConfig: { | ||
provider: "google", | ||
model: "gemini-1.5-pro", | ||
} | ||
}); | ||
|
||
const localExpertAgent = new Agent({ | ||
name: 'Sophia Lore', | ||
role: 'Local Expert at this city', | ||
goal: 'Provide the BEST insights about the selected city', | ||
background: `A knowledgeable local guide with extensive information about the city, it's attractions and customs`, | ||
type: 'ReactChampionAgent', | ||
tools: [searchInternet], | ||
maxIterations: 5, | ||
llmConfig: { | ||
provider: "google", | ||
model: "gemini-1.5-pro", | ||
} | ||
}); | ||
|
||
const travelConciergeAgent = new Agent({ | ||
name: 'Maxwell Journey', | ||
role: 'Amazing Travel Concierge', | ||
goal: `Create the most amazing travel itineraries with budget and packing suggestions for the city`, | ||
background: `Specialist in travel planning and logistics with decades of experience`, | ||
type: 'ReactChampionAgent', | ||
tools: [searchInternet], | ||
maxIterations: 5, | ||
llmConfig: { | ||
provider: "google", | ||
model: "gemini-1.5-pro", | ||
} | ||
}); | ||
|
||
// Define tasks with dynamic input placeholders | ||
const identifyTask = new Task({ | ||
description: `Analyze and select the best city for the trip based on | ||
specific criteria such as weather patterns, seasonal events, | ||
and travel costs. ... | ||
Origin: {origin}, City Options: {cities}, | ||
Trip Date: {range}, | ||
Traveler Interests: {interests}`, | ||
expectedOutput: `Detailed report on the chosen city, | ||
including flight costs, | ||
weather forecast and attractions`, | ||
agent: citySelectorAgent | ||
}); | ||
|
||
const gatherTask = new Task({ | ||
description: `Compile an in-depth guide for the selected city, | ||
considering key attractions, local customs, and special events. | ||
... Trip Date: {range}, Origin: {origin}, Interests: {interests}`, | ||
expectedOutput: `A comprehensive city guide, | ||
rich in cultural insights and practical tips`, | ||
agent: localExpertAgent | ||
}); | ||
|
||
const planTask = new Task({ | ||
description: `Develop a full 7-day travel itinerary | ||
with detailed daily plans, including places to eat, | ||
packing suggestions, and a budget breakdown. ... | ||
Trip Date: {range}, Origin: {origin}, Interests: {interests}`, | ||
expectedOutput: 'A complete expanded travel plan formatted as markdown', | ||
agent: travelConciergeAgent | ||
}); | ||
|
||
// Team to coordinate the agents, with dynamic inputs | ||
const tripPlanningTeam = new Team({ | ||
name: 'Trip Planning Team', | ||
agents: [citySelectorAgent, localExpertAgent, travelConciergeAgent], | ||
tasks: [identifyTask, gatherTask, planTask], | ||
logLevel: 'info', | ||
inputs: { | ||
origin: 'New York', | ||
cities: ['Tokyo', 'Paris', 'Berlin'], | ||
interests: 'Art and Culture', | ||
range: '2024-12-01 to 2024-12-15' | ||
}, // Actual dynamic inputs | ||
env: { | ||
OPENAI_API_KEY: import.meta.env.VITE_OPENAI_API_KEY, | ||
ANTHROPIC_API_KEY: import.meta.env.VITE_ANTHROPIC_API_KEY, | ||
GOOGLE_API_KEY: import.meta.env.VITE_GOOGLE_API_KEY | ||
} | ||
}); | ||
|
||
export default tripPlanningTeam; |
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
Oops, something went wrong.