Skip to content

Commit 51b32ed

Browse files
Python: Updates to Tools (microsoft#1835)
* updated tool samples * mypy and readme fixes * updated call logic * added function invocation config * added include detailed error * added tests * updated FRC exception handling * updated tests * fix oai test * fix name in sample * imporoved tests coverage and removed some dead code paths
1 parent d81b579 commit 51b32ed

19 files changed

Lines changed: 2460 additions & 119 deletions

python/packages/core/agent_framework/_clients.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
from ._serialization import SerializationMixin
2121
from ._threads import ChatMessageStoreProtocol
22-
from ._tools import ToolProtocol
22+
from ._tools import FUNCTION_INVOKING_CHAT_CLIENT_MARKER, FunctionInvocationConfiguration, ToolProtocol
2323
from ._types import ChatMessage, ChatOptions, ChatResponse, ChatResponseUpdate, ToolMode, prepare_messages
2424

2525
if TYPE_CHECKING:
@@ -357,6 +357,10 @@ def __init__(
357357

358358
self.middleware = middleware
359359

360+
self.function_invocation_configuration = (
361+
FunctionInvocationConfiguration() if hasattr(self.__class__, FUNCTION_INVOKING_CHAT_CLIENT_MARKER) else None
362+
)
363+
360364
def to_dict(self, *, exclude: set[str] | None = None, exclude_none: bool = True) -> dict[str, Any]:
361365
"""Convert the instance to a dictionary.
362366

python/packages/core/agent_framework/_tools.py

Lines changed: 345 additions & 103 deletions
Large diffs are not rendered by default.

python/packages/core/agent_framework/openai/_assistants_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ def _convert_function_results_to_tool_output(
502502
tool_outputs = []
503503
if function_result_content.result:
504504
output = prepare_function_call_results(function_result_content.result)
505-
elif function_result_content.exception:
506-
output = "Error: " + str(function_result_content.exception)
507505
else:
508506
output = "No output received."
509507
tool_outputs.append(ToolOutput(tool_call_id=call_id, output=output))

python/packages/core/agent_framework/openai/_chat_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ def _openai_chat_message_parser(self, message: ChatMessage) -> list[dict[str, An
380380
args["tool_call_id"] = content.call_id
381381
if content.result is not None:
382382
args["content"] = prepare_function_call_results(content.result)
383-
elif content.exception is not None:
384-
# Send the exception message to the model
385-
# Otherwise we won't have any channels to talk to OpenAI
386-
# TODO(yuge): This should ideally be customizable
387-
args["content"] = "Error: " + str(content.exception)
388383
case _:
389384
if "content" not in args:
390385
args["content"] = []

python/packages/core/agent_framework/openai/_responses_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ def _openai_content_parser(
501501
}
502502
if content.result:
503503
args["output"] = prepare_function_call_results(content.result)
504-
if content.exception:
505-
args["output"] = "Error: " + str(content.exception)
506504
return args
507505
case FunctionApprovalRequestContent():
508506
return {

0 commit comments

Comments
 (0)