You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Details:
- Adds the `LlmBackedUserSimulator` which uses an LLM to generate user prompts until it decides that the conversation is complete.
- Adds unit tests for the new functionality.
PiperOrigin-RevId: 823557910
Copy file name to clipboardExpand all lines: src/google/adk/evaluation/llm_backed_user_simulator.py
+182-2Lines changed: 182 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@
14
14
15
15
from __future__ importannotations
16
16
17
+
importlogging
17
18
fromtypingimportClassVar
18
19
fromtypingimportOptional
19
20
@@ -22,14 +23,79 @@
22
23
fromtyping_extensionsimportoverride
23
24
24
25
from ..events.eventimportEvent
26
+
from ..models.llm_requestimportLlmRequest
25
27
from ..models.registryimportLLMRegistry
28
+
from ..utils.context_utilsimportAclosing
26
29
from ..utils.feature_decoratorimportexperimental
27
30
from .conversation_scenariosimportConversationScenario
28
31
from .evaluatorimportEvaluator
29
32
from .user_simulatorimportBaseUserSimulatorConfig
30
33
from .user_simulatorimportNextUserMessage
34
+
from .user_simulatorimportStatus
31
35
from .user_simulatorimportUserSimulator
32
36
37
+
logger=logging.getLogger("google_adk."+__name__)
38
+
39
+
_AUTHOR_USER="user"
40
+
_STOP_SIGNAL="</finished>"
41
+
42
+
_USER_AGENT_INSTRUCTIONS_TEMPLATE="""You are a Simulated User designed to test an AI Agent.
43
+
44
+
Your single most important job is to react logically to the Agent's last message.
45
+
The Conversation Plan is your canonical grounding, not a script; your response MUST be dictated by what the Agent just said.
46
+
47
+
# Primary Operating Loop
48
+
49
+
You MUST follow this three-step process while thinking:
50
+
51
+
Step 1: Analyze what the Agent just said or did. Specifically, is the Agent asking you a question, reporting a successful or unsuccessful operation, or saying something incorrect or unexpected?
52
+
53
+
Step 2: Choose one action based on your analysis:
54
+
* ANSWER any questions the Agent asked.
55
+
* ADVANCE to the next request as per the Conversation Plan if the Agent succeeds in satisfying your current request.
56
+
* INTERVENE if the Agent is yet to complete your current request and the Conversation Plan requires you to modify it.
57
+
* CORRECT the Agent if it is making a mistake or failing.
58
+
* END the conversation if any of the below stopping conditions are met:
59
+
- The Agent has completed all your requests from the Conversation Plan.
60
+
- The Agent has failed to fulfill a request *more than once*.
61
+
- The Agent has performed an incorrect operation and informs you that it is unable to correct it.
62
+
- The Agent ends the conversation on its own by transferring you to a *human/live agent* (NOT another AI Agent).
63
+
64
+
Step 3: Formulate a response based on the chosen action and the below Action Protocols and output it.
65
+
66
+
# Action Protocols
67
+
68
+
**PROTOCOL: ANSWER**
69
+
* Only answer the Agent's questions using information from the Conversation Plan.
70
+
* Do NOT provide any additional information the Agent did not explicitly ask for.
71
+
* If you do not have the information requested by the Agent, inform the Agent. Do NOT make up information that is not in the Conversation Plan.
72
+
* Do NOT advance to the next request in the Conversation Plan.
73
+
74
+
**PROTOCOL: ADVANCE**
75
+
* Make the next request from the Conversation Plan.
76
+
* Skip redundant requests already fulfilled by the Agent.
77
+
78
+
**PROTOCOL: INTERVENE**
79
+
* Change your current request as directed by the Conversation Plan with natural phrasing.
80
+
81
+
**PROTOCOL: CORRECT**
82
+
* Challenge illogical or incorrect statements made by the Agent.
83
+
* If the Agent did an incorrect operation, ask the Agent to fix it.
84
+
* If this is the FIRST time the Agent failed to satisfy your request, ask the Agent to try again.
85
+
86
+
**PROTOCOL: END**
87
+
* End the conversation only when any of the stopping conditions are met; do NOT end prematurely.
88
+
* Output `{stop_signal}` to indicate that the conversation with the AI Agents is over.
0 commit comments