Ensure the `"Observation:"` tag is present after stopping, since stopping on that token prevents it from appearing in the output.
Browse filesWhen the `stop` sequence includes `"Observation:"`, the returned text ends before this tag appears in the output. As a result, the final message lacks the `"Observation:"` prefix, and the model has to generate a new observation that may not align with the actual result of the action. This can lead to hallucinated or incorrect agent behavior. By appending `"Observation:"` to the prompt manually after the model stops generating, we ensure the observation context is correctly set for the next step and that the model reacts to the actual output of the function.
unit1/dummy_agent_library.ipynb
CHANGED
@@ -449,7 +449,7 @@
|
|
449 |
"messages=[\n",
|
450 |
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
|
451 |
" {\"role\": \"user\", \"content\": \"What's the weather in London ?\"},\n",
|
452 |
-
" {\"role\": \"assistant\", \"content\": output.choices[0].message.content+get_weather('London')},\n",
|
453 |
"]\n",
|
454 |
"messages"
|
455 |
]
|
|
|
449 |
"messages=[\n",
|
450 |
" {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
|
451 |
" {\"role\": \"user\", \"content\": \"What's the weather in London ?\"},\n",
|
452 |
+
" {\"role\": \"assistant\", \"content\": output.choices[0].message.content+"Observation:\n"+get_weather('London')},\n",
|
453 |
"]\n",
|
454 |
"messages"
|
455 |
]
|