improved logging styling agent notebook

This commit is contained in:
starmorph
2025-05-13 09:44:12 -07:00
parent 9abff78aa8
commit 7d9178ebdf
+134 -144
View File
@@ -134,104 +134,101 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 70,
"id": "2307eec2-49e3-468c-b6e5-4a05850bbbd3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LLM Output from Cell 2: AIMessage {\n",
" \"id\": \"chatcmpl-BWar0J0Rf5BBhXUFDhMvCjjepUqrY\",\n",
" \"content\": \"\",\n",
" \"additional_kwargs\": {\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_ZdXESEXFrKiT7aFF7cLSkzVs\",\n",
" \"type\": \"function\",\n",
" \"function\": \"[Object]\"\n",
" }\n",
" ]\n",
" },\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"promptTokens\": 200,\n",
" \"completionTokens\": 101,\n",
" \"totalTokens\": 301\n",
" },\n",
" \"finish_reason\": \"tool_calls\",\n",
" \"model_name\": \"gpt-4.1-2025-04-14\",\n",
" \"usage\": {\n",
" \"prompt_tokens\": 200,\n",
" \"completion_tokens\": 101,\n",
" \"total_tokens\": 301,\n",
" \"prompt_tokens_details\": {\n",
" \"cached_tokens\": 0,\n",
" \"audio_tokens\": 0\n",
" },\n",
" \"completion_tokens_details\": {\n",
" \"reasoning_tokens\": 0,\n",
" \"audio_tokens\": 0,\n",
" \"accepted_prediction_tokens\": 0,\n",
" \"rejected_prediction_tokens\": 0\n",
" }\n",
" },\n",
" \"system_fingerprint\": \"fp_b38e740b47\"\n",
" },\n",
" \"tool_calls\": [\n",
" {\n",
" \"name\": \"write_email\",\n",
" \"args\": {\n",
" \"to\": \"sysadmin@company.com\",\n",
" \"subject\": \"Re: Scheduled maintenance - database downtime\",\n",
" \"content\": \"Hi System Admin Team,\\n\\nThank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\n\\nPlease let us know if there are any changes to the schedule or if you need any assistance from our side.\\n\\nBest regards,\\nDevelopment Team\"\n",
" },\n",
" \"type\": \"tool_call\",\n",
" \"id\": \"call_ZdXESEXFrKiT7aFF7cLSkzVs\"\n",
" }\n",
" ],\n",
" \"invalid_tool_calls\": [],\n",
" \"usage_metadata\": {\n",
" \"output_tokens\": 101,\n",
" \"input_tokens\": 200,\n",
" \"total_tokens\": 301,\n",
" \"input_token_details\": {\n",
" \"audio\": 0,\n",
" \"cache_read\": 0\n",
" },\n",
" \"output_token_details\": {\n",
" \"audio\": 0,\n",
" \"reasoning\": 0\n",
" }\n",
" }\n",
"}\n",
"Tool Calls from Cell 2: [\n",
" {\n",
" name: 'write_email',\n",
" args: {\n",
" to: 'sysadmin@company.com',\n",
" subject: 'Re: Scheduled maintenance - database downtime',\n",
" content: 'Hi System Admin Team,\\n' +\n",
" '\\n' +\n",
" 'Thank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\n' +\n",
" '\\n' +\n",
" 'Please let us know if there are any changes to the schedule or if you need any assistance from our side.\\n' +\n",
" '\\n' +\n",
" 'Best regards,\\n' +\n",
" 'Development Team'\n",
" },\n",
" type: 'tool_call',\n",
" id: 'call_ZdXESEXFrKiT7aFF7cLSkzVs'\n",
" }\n",
"]\n"
]
"data": {
"text/markdown": [
"```json\n",
"{\n",
" \"lc\": 1,\n",
" \"type\": \"constructor\",\n",
" \"id\": [\n",
" \"langchain_core\",\n",
" \"messages\",\n",
" \"AIMessage\"\n",
" ],\n",
" \"kwargs\": {\n",
" \"content\": \"\",\n",
" \"additional_kwargs\": {\n",
" \"tool_calls\": [\n",
" {\n",
" \"id\": \"call_SqpPQh4RBK6GnkLvYIOCmdkh\",\n",
" \"type\": \"function\",\n",
" \"function\": {\n",
" \"name\": \"write_email\",\n",
" \"arguments\": \"{\\\"to\\\":\\\"sysadmin@company.com\\\",\\\"subject\\\":\\\"Re: Scheduled maintenance - database downtime\\\",\\\"content\\\":\\\"Hi System Admin Team,\\\\n\\\\nThank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\\\n\\\\nPlease let us know if there are any changes to the schedule or if you need any assistance from our side.\\\\n\\\\nBest regards,\\\\nDevelopment Team\\\"}\"\n",
" }\n",
" }\n",
" ]\n",
" },\n",
" \"response_metadata\": {\n",
" \"tokenUsage\": {\n",
" \"promptTokens\": 200,\n",
" \"completionTokens\": 101,\n",
" \"totalTokens\": 301\n",
" },\n",
" \"finish_reason\": \"tool_calls\",\n",
" \"model_name\": \"gpt-4.1-2025-04-14\",\n",
" \"usage\": {\n",
" \"prompt_tokens\": 200,\n",
" \"completion_tokens\": 101,\n",
" \"total_tokens\": 301,\n",
" \"prompt_tokens_details\": {\n",
" \"cached_tokens\": 0,\n",
" \"audio_tokens\": 0\n",
" },\n",
" \"completion_tokens_details\": {\n",
" \"reasoning_tokens\": 0,\n",
" \"audio_tokens\": 0,\n",
" \"accepted_prediction_tokens\": 0,\n",
" \"rejected_prediction_tokens\": 0\n",
" }\n",
" },\n",
" \"system_fingerprint\": \"fp_b38e740b47\"\n",
" },\n",
" \"id\": \"chatcmpl-BWn0Szledi9VKeejurtMTfJNvY0XP\",\n",
" \"tool_calls\": [\n",
" {\n",
" \"name\": \"write_email\",\n",
" \"args\": {\n",
" \"to\": \"sysadmin@company.com\",\n",
" \"subject\": \"Re: Scheduled maintenance - database downtime\",\n",
" \"content\": \"Hi System Admin Team,\\n\\nThank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\n\\nPlease let us know if there are any changes to the schedule or if you need any assistance from our side.\\n\\nBest regards,\\nDevelopment Team\"\n",
" },\n",
" \"type\": \"tool_call\",\n",
" \"id\": \"call_SqpPQh4RBK6GnkLvYIOCmdkh\"\n",
" }\n",
" ],\n",
" \"invalid_tool_calls\": [],\n",
" \"usage_metadata\": {\n",
" \"output_tokens\": 101,\n",
" \"input_tokens\": 200,\n",
" \"total_tokens\": 301,\n",
" \"input_token_details\": {\n",
" \"audio\": 0,\n",
" \"cache_read\": 0\n",
" },\n",
" \"output_token_details\": {\n",
" \"audio\": 0,\n",
" \"reasoning\": 0\n",
" }\n",
" }\n",
" }\n",
"}\n",
"```"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import { initChatModel } from \"langchain/chat_models/universal\";\n",
"import { AIMessage } from \"@langchain/core/messages\";\n",
"\n",
"import * as tslab from \"tslab\";\n",
"// Declare 'output' in a scope accessible by subsequent cells\n",
"let output: AIMessage | null = null;\n",
"\n",
@@ -258,54 +255,50 @@
"\n",
"output = await llmWithTools.invoke(messages);\n",
"\n",
"console.log(\"LLM Output from Cell 2:\", output);\n",
"\n",
"if (output && output.tool_calls) {\n",
" console.log(\"Tool Calls from Cell 2:\", output.tool_calls);\n",
" tslab.display.markdown(\"```json\\n\" + JSON.stringify(output, null, 2) + \"\\n```\");\n",
"} else {\n",
" console.log(\"No tool calls found in the output from Cell 2.\");\n",
"}"
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 86,
"id": "434fe1b1-6363-40ce-ad33-df03145ba8d5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\n",
" {\n",
" name: 'write_email',\n",
" args: {\n",
" to: 'sysadmin@company.com',\n",
" subject: 'Re: Scheduled maintenance - database downtime',\n",
" content: 'Hi System Admin Team,\\n' +\n",
" '\\n' +\n",
" 'Thank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\n' +\n",
" '\\n' +\n",
" 'Please let us know if there are any changes to the schedule or if you need any assistance from our side.\\n' +\n",
" '\\n' +\n",
" 'Best regards,\\n' +\n",
" 'Development Team'\n",
" },\n",
" type: 'tool_call',\n",
" id: 'call_ZdXESEXFrKiT7aFF7cLSkzVs'\n",
" }\n",
"]\n"
]
"data": {
"text/markdown": [
"```json\n",
"[\n",
" {\n",
" \"name\": \"write_email\",\n",
" \"args\": {\n",
" \"to\": \"sysadmin@company.com\",\n",
" \"subject\": \"Re: Scheduled maintenance - database downtime\",\n",
" \"content\": \"Hi System Admin Team,\\n\\nThank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\n\\nPlease let us know if there are any changes to the schedule or if you need any assistance from our side.\\n\\nBest regards,\\nDevelopment Team\"\n",
" },\n",
" \"type\": \"tool_call\",\n",
" \"id\": \"call_SqpPQh4RBK6GnkLvYIOCmdkh\"\n",
" }\n",
"]\n",
"```"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"console.log(output.tool_calls);"
"tslab.display.markdown(\"```json\\n\" + JSON.stringify(output.tool_calls, null, 2) + \"\\n```\");"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 87,
"id": "6393f3ed-90cd-4c86-a528-af5c0a9c43b2",
"metadata": {},
"outputs": [],
@@ -315,28 +308,25 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 101,
"id": "7e721597-0e17-44ea-9b7e-a9e1fee438de",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Email sent to sysadmin@company.com with subject 'Re: Scheduled maintenance - database downtime' and content: Hi System Admin Team,\n",
"\n",
"Thank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\n",
"\n",
"Please let us know if there are any changes to the schedule or if you need any assistance from our side.\n",
"\n",
"Best regards,\n",
"Development Team\n"
]
"data": {
"text/markdown": [
"```json\n",
"\"Email sent to sysadmin@company.com with subject 'Re: Scheduled maintenance - database downtime' and content: Hi System Admin Team,\\n\\nThank you for the reminder. We have noted the scheduled maintenance window and will ensure that no critical deployments or database-dependent tasks are planned during this time.\\n\\nPlease let us know if there are any changes to the schedule or if you need any assistance from our side.\\n\\nBest regards,\\nDevelopment Team\"\n",
"```"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"const writeEmailResult = await writeEmail.invoke(args);\n",
"console.log(writeEmailResult);"
"tslab.display.markdown(\"```json\\n\" + JSON.stringify(writeEmailResult, null, 2) + \"\\n```\");"
]
},
{
@@ -369,7 +359,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 102,
"id": "692537ec-f09e-4086-81e4-9c517273b854",
"metadata": {},
"outputs": [],
@@ -406,7 +396,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 103,
"id": "c54ae6a6-94d9-4160-8d45-18f4d29aa600",
"metadata": {},
"outputs": [],
@@ -615,7 +605,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 104,
"id": "8f69c6fc-70aa-48f1-8312-2b1818469a1b",
"metadata": {},
"outputs": [],
@@ -631,7 +621,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 105,
"id": "9052fced-3fdb-4cd2-ac88-e2ccdce14e7c",
"metadata": {},
"outputs": [],
@@ -675,7 +665,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 106,
"id": "6f2c120f",
"metadata": {},
"outputs": [],
@@ -798,7 +788,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 107,
"id": "43eb6dc2",
"metadata": {},
"outputs": [],
@@ -846,7 +836,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 108,
"id": "7c7cbea7",
"metadata": {},
"outputs": [],
@@ -888,7 +878,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 109,
"id": "f81df767",
"metadata": {},
"outputs": [],
@@ -958,7 +948,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 110,
"id": "2dd6dcc4-6346-4d41-ae36-61f3fc83b7a7",
"metadata": {},
"outputs": [],
@@ -991,7 +981,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 111,
"id": "070f18a6",
"metadata": {},
"outputs": [
@@ -1022,7 +1012,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 112,
"id": "7a50ae0a-7bd1-4e69-90be-781b1e77b4dd",
"metadata": {},
"outputs": [
@@ -1081,7 +1071,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 113,
"id": "08ee005a",
"metadata": {},
"outputs": [],