Skip to content

Commit 1fe01d2

Browse files
authored
Update BaseLLM.chat and BaseLLM.continue_conversation_with_tool_call_results for better consistency (#84)
* update chat and continue_conversation_with_tool_results return types * fix agent tests * fix tests * update ollama * update ollama tests * ensure agent nb works * changelog
1 parent 09c4d7f commit 1fe01d2

File tree

9 files changed

+356
-174
lines changed

9 files changed

+356
-174
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1616

1717
### Changed
1818

19+
- Update `BaseLLM.chat` and `BaseLLM.continue_conversation_with_tool_call_results` for better consistency (#84)
1920
- Refactor: Change LLMAgent.run helper method _run name to_process_loop (#83)
2021
- Remove TaskHandler._lock since we actually don't need it (#79)
2122
- [Fix] Move check for previous_step_result at top of method (#76)

docs/notebooks/first_llm_agent.ipynb

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
"from llm_agents_from_scratch.logger import enable_console_logging\n",
186186
"\n",
187187
"if LOGGING_ENABLED:\n",
188-
" enable_console_logging(logging.INFO)"
188+
" enable_console_logging(logging.DEBUG)"
189189
]
190190
},
191191
{
@@ -213,6 +213,27 @@
213213
{
214214
"cell_type": "code",
215215
"execution_count": 13,
216+
"id": "980b29c6-bf26-439c-9458-0cab040e854b",
217+
"metadata": {},
218+
"outputs": [
219+
{
220+
"data": {
221+
"text/plain": [
222+
"Task(id_='25aa12c3-ae1a-415c-a186-102b4412c268', instruction='Add one to fifty-five point three. Use an appropriate tool!')"
223+
]
224+
},
225+
"execution_count": 13,
226+
"metadata": {},
227+
"output_type": "execute_result"
228+
}
229+
],
230+
"source": [
231+
"task"
232+
]
233+
},
234+
{
235+
"cell_type": "code",
236+
"execution_count": 14,
216237
"id": "e99cca54-0d21-4c9d-9a17-bf595d110fe5",
217238
"metadata": {},
218239
"outputs": [
@@ -222,11 +243,62 @@
222243
"text": [
223244
"INFO (llm_agents_fs.LLMAgent) : 🚀 Starting task: Add one to fifty-five point three. Use an appropriate tool!\n",
224245
"INFO (llm_agents_fs.TaskHandler) : ⚙️ Processing Step: Add one to fifty-five point three. Use an appropriate tool!\n",
246+
"DEBUG (llm_agents_fs.TaskHandler) : 🧵 Rollout: \n",
247+
"DEBUG (llm_agents_fs.TaskHandler) : 💬 SYSTEM: You are a helpful assistant.\n",
248+
"DEBUG (llm_agents_fs.TaskHandler) : 💬 USER INPUT: Add one to fifty-five point three. Use an appropriate tool!\n",
249+
"DEBUG (llm_agents_fs.TaskHandler) : 💬 ASSISTANT: \n",
225250
"INFO (llm_agents_fs.TaskHandler) : 🛠️ Executing Tool Call: add_one\n",
226251
"INFO (llm_agents_fs.TaskHandler) : ✅ Successful Tool Call: 56.3\n",
227-
"INFO (llm_agents_fs.TaskHandler) : ✅ Step Result: Adding one to fifty-five point three gives us fifty-six point three.\n",
252+
"INFO (llm_agents_fs.TaskHandler) : ✅ Step Result: The result of adding one to 55.3 is 56.3.\n",
253+
"DEBUG (llm_agents_fs.TaskHandler) : 🧵 Rollout: assistant: The current instruction is 'Add one to fifty-five point three. Use an appropriate tool!'\n",
254+
"assistant: I need to make a tool call(s) to `add_one`.\n",
255+
"tool: {\n",
256+
" \"tool_call\": {\n",
257+
" \"tool_name\": \"add_one\",\n",
258+
" \"arguments\": {\n",
259+
" \"x\": \"55.3\"\n",
260+
" }\n",
261+
" },\n",
262+
" \"content\": \"56.3\",\n",
263+
" \"error\": false\n",
264+
"}\n",
265+
"assistant: The result of adding one to 55.3 is 56.3.\n",
266+
"DEBUG (llm_agents_fs.TaskHandler) : ---NEXT STEP PROMPT: You are overseeing an assistant's\n",
267+
"progress in accomplishing a user instruction. Provided below is the assistant's\n",
268+
"current response to the original task instruction. Also provided, is an\n",
269+
"internal 'thinking' process of the assistant that the user has not seen.\n",
270+
"\n",
271+
"Determine if the current the response is sufficient to answer the original task\n",
272+
"instruction. In the case that it is not, provide a new instruction to the\n",
273+
"assistant in order to help them improve upon their current response.\n",
274+
"\n",
275+
"<user-instruction>\n",
276+
"Add one to fifty-five point three. Use an appropriate tool!\n",
277+
"</user-instruction>\n",
278+
"\n",
279+
"<current-response>\n",
280+
"The result of adding one to 55.3 is 56.3.\n",
281+
"</current-response>\n",
282+
"\n",
283+
"<thinking-process>\n",
284+
"assistant: The current instruction is 'Add one to fifty-five point three. Use an appropriate tool!'\n",
285+
"assistant: I need to make a tool call(s) to `add_one`.\n",
286+
"tool: {\n",
287+
" \"tool_call\": {\n",
288+
" \"tool_name\": \"add_one\",\n",
289+
" \"arguments\": {\n",
290+
" \"x\": \"55.3\"\n",
291+
" }\n",
292+
" },\n",
293+
" \"content\": \"56.3\",\n",
294+
" \"error\": false\n",
295+
"}\n",
296+
"assistant: The result of adding one to 55.3 is 56.3.\n",
297+
"</thinking-process>\n",
298+
"\n",
299+
"DEBUG (llm_agents_fs.TaskHandler) : ---NEXT STEP: {\"task_step\":{\"id_\":\"915cca85-0b6b-477d-921e-0dce7b8b3533\",\"task_id\":\"add-one-to-55-point-three\",\"instruction\":\"Add one to fifty-five point three using the tool add_one.\"},\"task_result\":{\"task_id\":\"add-one-to-55-point-three\",\"content\":\"The result of adding one to 55.3 is 56.3.\"}}\n",
228300
"INFO (llm_agents_fs.TaskHandler) : No new step required.\n",
229-
"INFO (llm_agents_fs.LLMAgent) : 🏁 Task completed: Adding one to fifty-five point three gives us fifty-six point three.\n"
301+
"INFO (llm_agents_fs.LLMAgent) : 🏁 Task completed: The result of adding one to 55.3 is 56.3.\n"
230302
]
231303
}
232304
],
@@ -236,15 +308,36 @@
236308
},
237309
{
238310
"cell_type": "code",
239-
"execution_count": 14,
311+
"execution_count": 15,
312+
"id": "3615a1c9-8a1d-4783-a840-e186206d9446",
313+
"metadata": {},
314+
"outputs": [
315+
{
316+
"data": {
317+
"text/plain": [
318+
"TaskResult(task_id='25aa12c3-ae1a-415c-a186-102b4412c268', content='The result of adding one to 55.3 is 56.3.')"
319+
]
320+
},
321+
"execution_count": 15,
322+
"metadata": {},
323+
"output_type": "execute_result"
324+
}
325+
],
326+
"source": [
327+
"result.task_result"
328+
]
329+
},
330+
{
331+
"cell_type": "code",
332+
"execution_count": 16,
240333
"id": "0fde7c61-f0d9-4ef9-b0b6-90386667bbb8",
241334
"metadata": {},
242335
"outputs": [
243336
{
244337
"name": "stdout",
245338
"output_type": "stream",
246339
"text": [
247-
"The result is fifty-six point three.\n"
340+
"The result of adding one to 55.3 is 56.3.\n"
248341
]
249342
}
250343
],
@@ -254,16 +347,16 @@
254347
},
255348
{
256349
"cell_type": "code",
257-
"execution_count": 15,
350+
"execution_count": 17,
258351
"id": "93b1cfa1-1ac0-420d-b36e-007de5cdfc7f",
259352
"metadata": {},
260353
"outputs": [
261354
{
262355
"name": "stdout",
263356
"output_type": "stream",
264357
"text": [
265-
"assistant: Add one to fifty-five point three. Use an appropriate tool!\n",
266-
"assistant: I need to make a tool call(s) to add_one\n",
358+
"assistant: The current instruction is 'Add one to fifty-five point three. Use an appropriate tool!'\n",
359+
"assistant: I need to make a tool call(s) to `add_one`.\n",
267360
"tool: {\n",
268361
" \"tool_call\": {\n",
269362
" \"tool_name\": \"add_one\",\n",
@@ -274,21 +367,13 @@
274367
" \"content\": \"56.3\",\n",
275368
" \"error\": false\n",
276369
"}\n",
277-
"assistant: Adding one to fifty-five point three gives us fifty-six point three.\n"
370+
"assistant: The result of adding one to 55.3 is 56.3.\n"
278371
]
279372
}
280373
],
281374
"source": [
282375
"print(result.rollout)"
283376
]
284-
},
285-
{
286-
"cell_type": "code",
287-
"execution_count": null,
288-
"id": "e1a01698-dcdc-4796-a41b-6029eafa9ab5",
289-
"metadata": {},
290-
"outputs": [],
291-
"source": []
292377
}
293378
],
294379
"metadata": {

0 commit comments

Comments
 (0)