Add agentic module: sequential, parallel, loop, supervisor and error-recovery workflows
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01G8ikz8xdWuTP5yun8DZ1hk
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
Order the agents ran in:
|
||||
findFlight read [traveler, destination] and wrote AI-101 Mumbai to Lisbon
|
||||
findHotel read [traveler, destination] and wrote Hotel Alfama
|
||||
findActivity read [traveler, destination] and wrote Tram 28
|
||||
write read [hotels, activities, destination, flights] and wrote Fly AI-101, stay at Hotel Alfama, ride Tram 28.
|
||||
|
||||
Shared state at the end:
|
||||
traveler = Ankur
|
||||
hotels = Hotel Alfama
|
||||
activities = Tram 28
|
||||
destination = Lisbon
|
||||
flights = AI-101 Mumbai to Lisbon
|
||||
plan = Fly AI-101, stay at Hotel Alfama, ride Tram 28.
|
||||
|
||||
The prompt the planner was sent (last model call):
|
||||
Write a one-line itinerary for Lisbon. Flight: AI-101 Mumbai to Lisbon. Hotel: Hotel Alfama. Activity: Tram 28.
|
||||
|
||||
Model calls: 4
|
||||
@@ -0,0 +1,11 @@
|
||||
A) Planner declares only @V destination, template mentions {{flights}} {{hotels}} {{activities}}.
|
||||
omit nothing: Value for the variable 'hotels' is missing
|
||||
omit flights: Value for the variable 'hotels' is missing
|
||||
omit hotels: Value for the variable 'hotels' is missing
|
||||
omit activities: Value for the variable 'hotels' is missing
|
||||
|
||||
B) Planner declares @V destination, @V flights, @V hotels, @V activities.
|
||||
omit nothing: OK: Fly AI-101, stay at Hotel Alfama, ride Tram 28.
|
||||
omit flights: Missing argument: flights
|
||||
omit hotels: Missing argument: hotels
|
||||
omit activities: Missing argument: activities
|
||||
@@ -0,0 +1,9 @@
|
||||
Three finders, each model call sleeps 300 ms.
|
||||
|
||||
#27 start 0 ms end 301 ms
|
||||
#31 start 1 ms end 302 ms
|
||||
#29 start 0 ms end 302 ms
|
||||
|
||||
Distinct threads: 3
|
||||
Wall clock for the whole sequence: 320 ms (sequential would be at least 900 ms)
|
||||
Plan: Fly AI-101, stay at Hotel Alfama, ride Tram 28.
|
||||
@@ -0,0 +1,4 @@
|
||||
Scorer replies 5, 7, 9, 10. Exit condition: score >= 8. maxIterations 5.
|
||||
|
||||
testExitAtLoopEnd = false (default): final plan 'draft 3', scorer ran 3 times, improver ran 2 times, final score 9
|
||||
testExitAtLoopEnd = true: final plan 'draft 4', scorer ran 3 times, improver ran 3 times, final score 9
|
||||
@@ -0,0 +1,44 @@
|
||||
Supervisor model was scripted to reply with three JSON decisions.
|
||||
|
||||
Answer: Hotel Alfama
|
||||
|
||||
Worker calls: 2
|
||||
List one flight option to Lisbon for Ankur.
|
||||
List one hotel option in Lisbon for Ankur.
|
||||
|
||||
Supervisor model calls: 3
|
||||
|
||||
First prompt the supervisor saw:
|
||||
The user request is: 'Find me a flight and a hotel for Lisbon'.
|
||||
The last received response is: ''.
|
||||
|
||||
You must answer strictly in the following JSON format: {
|
||||
"agentName": (type: string),
|
||||
"arguments": (type: java.util.Map<java.lang.String, java.lang.Object>)
|
||||
}
|
||||
|
||||
What each responseStrategy returned for the same three decisions:
|
||||
(default) Hotel Alfama
|
||||
SCORED Flight AI-101 and Hotel Alfama booked options found. (supervisor calls: 4)
|
||||
|
||||
The extra SCORED call asked the supervisor model:
|
||||
You are a response evaluator that is provided with two responses to a user request.
|
||||
Your role is to score the two responses based on their relevance for the user request.
|
||||
|
||||
For each of the two responses, response1 and response2, you will return a score, respectively score 1 and score 2,
|
||||
between 0.0 and 1.0, where 0.0 means the response is completely irrelevant to the user request,
|
||||
and 1.0 means the response is perfectly relevant to the user request.
|
||||
|
||||
Return only the score and nothing else, without any additional text or explanation.
|
||||
|
||||
The user request is: 'Find me a flight and a hotel for Lisbon'.
|
||||
The first response is: 'Hotel Alfama'.
|
||||
The second response is: 'Flight AI-101 and Hotel Alfama booked options found.'.
|
||||
|
||||
You must answer strictly in the following JSON format: {
|
||||
"score1": (type: double),
|
||||
"score2": (type: double)
|
||||
}
|
||||
|
||||
SUMMARY Flight AI-101 and Hotel Alfama booked options found. (supervisor calls: 3)
|
||||
LAST Hotel Alfama (supervisor calls: 3)
|
||||
@@ -0,0 +1,7 @@
|
||||
A) Supervisor model never says done, maxAgentsInvocations = 2.
|
||||
returned: AI-101 Mumbai to Lisbon
|
||||
worker calls: 2, supervisor calls: 2
|
||||
|
||||
B) Supervisor model replies in prose instead of JSON.
|
||||
threw: JsonParseException: Unrecognized token 'Sure': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
|
||||
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1]
|
||||
@@ -0,0 +1,32 @@
|
||||
Two agents, both with a method named find. What the supervisor model was shown:
|
||||
|
||||
SYSTEM: SystemMessage { text = "You are a planner expert that is provided with a set of agents.
|
||||
You know nothing about any domain, don't take any assumptions about the user request,
|
||||
the only thing that you can do is rely on the provided agents.
|
||||
|
||||
Your role is to analyze the user request and decide which one of the provided agents to call next to address it.
|
||||
You return an agent invocation consisting of the name of the agent and the arguments to pass to it.
|
||||
|
||||
If no further agent requests are required, return an agentName of "done" and an argument named
|
||||
"response", where the value of the response argument is a recap of all the performed actions,
|
||||
written in the same language as the user request.
|
||||
|
||||
Agents are provided with their name and description together with a list of applicable arguments
|
||||
in the format {'name', 'description', [argument1: type1, argument2: type2]}.
|
||||
|
||||
Decide which agent to invoke next, doing things in small steps and
|
||||
never taking any shortcuts or relying on your own knowledge.
|
||||
Even if the user's request is already clear or explicit, don't make any assumptions and use the agents.
|
||||
Be sure to query ALL necessary agents.
|
||||
|
||||
The comma separated list of available agents is: '{'find$0', 'Finds a train', [destination: String]}, {'find$1', 'Finds a bus', [destination: String]}'.
|
||||
|
||||
|
||||
", attributes = {} }
|
||||
USER: UserMessage { name = null, contents = [TextContent { text = "The user request is: 'Get me to Lisbon'.
|
||||
The last received response is: ''.
|
||||
|
||||
You must answer strictly in the following JSON format: {
|
||||
"agentName": (type: string),
|
||||
"arguments": (type: java.util.Map<java.lang.String, java.lang.Object>)
|
||||
}" }], attributes = {} }
|
||||
@@ -0,0 +1,6 @@
|
||||
FlakyAgent's model throws on its first N calls.
|
||||
|
||||
no handler, N=1: Attempt[outcome=threw IllegalStateException: model unavailable (attempt 1), modelCalls=1]
|
||||
handler retry(), N=2: Attempt[outcome=returned 'AI-101 Mumbai to Lisbon', modelCalls=3] (handler invoked 2 times)
|
||||
handler result(".."), N=5: Attempt[outcome=returned 'no flight found, ask the traveler', modelCalls=1]
|
||||
handler throwException(), N=5: Attempt[outcome=threw IllegalStateException: model unavailable (attempt 1), modelCalls=1]
|
||||
Reference in New Issue
Block a user