Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,6 @@ FodyWeavers.xsd

# Ignore PNG files in the specified directory
02-explore-agentic-frameworks/code_samples/*.png

# Ignore backup files
*-backup.ipynb
31 changes: 30 additions & 1 deletion 04-tool-use/code_samples/04-semantic-kernel-tool.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
" agent_name = None\n",
" full_response: list[str] = []\n",
" function_calls: list[str] = []\n",
" function_calls_made = [] # Track function calls that were detected\n",
"\n",
" # Buffer to reconstruct streaming function call\n",
" current_function_name = None\n",
Expand All @@ -247,7 +248,24 @@
" # Accumulate arguments (streamed in chunks)\n",
" if isinstance(item.arguments, str):\n",
" argument_buffer += item.arguments\n",
" \n",
" # For the current semantic-kernel version, finalize function call immediately\n",
" # since FunctionResultContent may not be streamed\n",
" if current_function_name and argument_buffer:\n",
" formatted_args = argument_buffer.strip()\n",
" try:\n",
" parsed_args = json.loads(formatted_args)\n",
" formatted_args = json.dumps(parsed_args)\n",
" except Exception:\n",
" pass # leave as raw string\n",
"\n",
" function_calls_made.append({\n",
" 'name': current_function_name,\n",
" 'args': formatted_args\n",
" })\n",
" \n",
" elif isinstance(item, FunctionResultContent):\n",
" # This handles the case if FunctionResultContent is available (newer versions)\n",
" # Finalize any pending function call before showing result\n",
" if current_function_name:\n",
" formatted_args = argument_buffer.strip()\n",
Expand All @@ -265,6 +283,17 @@
" elif isinstance(item, StreamingTextContent) and item.text:\n",
" full_response.append(item.text)\n",
"\n",
" # If we detected function calls but didn't get FunctionResultContent in streaming,\n",
" # we can infer that functions were called successfully since we got a response\n",
" if function_calls_made and not function_calls:\n",
" for func_call in function_calls_made:\n",
" function_calls.append(f\"Calling function: {func_call['name']}({func_call['args']})\")\n",
" \n",
" # Since we know functions were called and we have a response, \n",
" # we can indicate that function results were processed\n",
" if len(function_calls_made) > 0:\n",
" function_calls.append(\"\\nFunction results were processed successfully (results used to generate the response above)\")\n",
"\n",
" if function_calls:\n",
" html_output += (\n",
" \"<div style='margin-bottom:10px'>\"\n",
Expand Down Expand Up @@ -309,4 +338,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}