Skip to content

Commit 21215da

Browse files
Fix tool normalization and provider samples
- restore callable/single-tool normalization paths and unset tool-choice behavior\n- consolidate and expand chat/provider samples (OpenAI/Azure/Anthropic/Ollama/Bedrock)\n- migrate Bedrock lazy import surface to agent_framework.amazon and move provider samples Co-authored-by: Copilot <[email protected]>
1 parent b68d0f9 commit 21215da

47 files changed

Lines changed: 784 additions & 805 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

python/packages/bedrock/AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Integration with AWS Bedrock for LLM inference.
1212
## Usage
1313

1414
```python
15-
from agent_framework_bedrock import BedrockChatClient
15+
from agent_framework.amazon import BedrockChatClient
1616

1717
client = BedrockChatClient(model_id="anthropic.claude-3-sonnet-20240229-v1:0")
1818
response = await client.get_response("Hello")
@@ -21,5 +21,5 @@ response = await client.get_response("Hello")
2121
## Import Path
2222

2323
```python
24-
from agent_framework_bedrock import BedrockChatClient
24+
from agent_framework.amazon import BedrockChatClient
2525
```

python/packages/bedrock/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The Bedrock integration enables Microsoft Agent Framework applications to call A
1212

1313
### Basic Usage Example
1414

15-
See the [Bedrock sample script](samples/bedrock_sample.py) for a runnable end-to-end script that:
15+
See the [Bedrock sample script](../../samples/02-agents/providers/bedrock/bedrock_chat_client.py) for a runnable end-to-end script that:
1616

1717
- Loads credentials from the `BEDROCK_*` environment variables
1818
- Instantiates `BedrockChatClient`

python/packages/bedrock/agent_framework_bedrock/_chat_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def __init__(
260260
Examples:
261261
.. code-block:: python
262262
263-
from agent_framework.bedrock import BedrockChatClient
263+
from agent_framework.amazon import BedrockChatClient
264264
265265
# Basic usage with default credentials
266266
client = BedrockChatClient(model_id="<model name>")

python/packages/bedrock/samples/__init__.py

Whitespace-only changes.

python/packages/bedrock/samples/bedrock_sample.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

python/packages/core/agent_framework/_agents.py

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from ._tools import (
3838
FunctionInvocationLayer,
3939
FunctionTool,
40+
ToolTypes,
41+
normalize_tools,
4042
)
4143
from ._types import (
4244
AgentResponse,
@@ -616,12 +618,7 @@ def __init__(
616618
id: str | None = None,
617619
name: str | None = None,
618620
description: str | None = None,
619-
tools: FunctionTool
620-
| Callable[..., Any]
621-
| MutableMapping[str, Any]
622-
| Any
623-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
624-
| None = None,
621+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
625622
default_options: OptionsCoT | None = None,
626623
context_providers: Sequence[BaseContextProvider] | None = None,
627624
**kwargs: Any,
@@ -667,24 +664,14 @@ def __init__(
667664

668665
# Get tools from options or named parameter (named param takes precedence)
669666
tools_ = tools if tools is not None else opts.pop("tools", None)
670-
tools_ = cast(
671-
FunctionTool
672-
| Callable[..., Any]
673-
| MutableMapping[str, Any]
674-
| list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
675-
| None,
676-
tools_,
677-
)
678667

679668
# Handle instructions - named parameter takes precedence over options
680669
instructions_ = instructions if instructions is not None else opts.pop("instructions", None)
681670

682671
# We ignore the MCP Servers here and store them separately,
683672
# we add their functions to the tools list at runtime
684-
normalized_tools: list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]] = ( # type:ignore[reportUnknownVariableType]
685-
[] if tools_ is None else tools_ if isinstance(tools_, list) else [tools_] # type: ignore[list-item]
686-
)
687-
self.mcp_tools: list[MCPTool] = [tool for tool in normalized_tools if isinstance(tool, MCPTool)] # type: ignore[misc]
673+
normalized_tools = normalize_tools(tools_)
674+
self.mcp_tools: list[MCPTool] = [tool for tool in normalized_tools if isinstance(tool, MCPTool)]
688675
agent_tools = [tool for tool in normalized_tools if not isinstance(tool, MCPTool)]
689676

690677
# Build chat options dict
@@ -767,12 +754,7 @@ def run(
767754
*,
768755
stream: Literal[False] = ...,
769756
session: AgentSession | None = None,
770-
tools: FunctionTool
771-
| Callable[..., Any]
772-
| MutableMapping[str, Any]
773-
| Any
774-
| list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
775-
| None = None,
757+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
776758
options: ChatOptions[ResponseModelBoundT],
777759
**kwargs: Any,
778760
) -> Awaitable[AgentResponse[ResponseModelBoundT]]: ...
@@ -784,12 +766,7 @@ def run(
784766
*,
785767
stream: Literal[False] = ...,
786768
session: AgentSession | None = None,
787-
tools: FunctionTool
788-
| Callable[..., Any]
789-
| MutableMapping[str, Any]
790-
| Any
791-
| list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
792-
| None = None,
769+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
793770
options: OptionsCoT | ChatOptions[None] | None = None,
794771
**kwargs: Any,
795772
) -> Awaitable[AgentResponse[Any]]: ...
@@ -801,12 +778,7 @@ def run(
801778
*,
802779
stream: Literal[True],
803780
session: AgentSession | None = None,
804-
tools: FunctionTool
805-
| Callable[..., Any]
806-
| MutableMapping[str, Any]
807-
| Any
808-
| list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
809-
| None = None,
781+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
810782
options: OptionsCoT | ChatOptions[Any] | None = None,
811783
**kwargs: Any,
812784
) -> ResponseStream[AgentResponseUpdate, AgentResponse[Any]]: ...
@@ -817,12 +789,7 @@ def run(
817789
*,
818790
stream: bool = False,
819791
session: AgentSession | None = None,
820-
tools: FunctionTool
821-
| Callable[..., Any]
822-
| MutableMapping[str, Any]
823-
| Any
824-
| list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
825-
| None = None,
792+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
826793
options: OptionsCoT | ChatOptions[Any] | None = None,
827794
**kwargs: Any,
828795
) -> Awaitable[AgentResponse[Any]] | ResponseStream[AgentResponseUpdate, AgentResponse[Any]]:
@@ -1002,12 +969,7 @@ async def _prepare_run_context(
1002969
*,
1003970
messages: str | Message | Sequence[str | Message] | None,
1004971
session: AgentSession | None,
1005-
tools: FunctionTool
1006-
| Callable[..., Any]
1007-
| MutableMapping[str, Any]
1008-
| Any
1009-
| list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
1010-
| None,
972+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None,
1011973
options: Mapping[str, Any] | None,
1012974
kwargs: dict[str, Any],
1013975
) -> _RunContext:
@@ -1037,9 +999,7 @@ async def _prepare_run_context(
1037999
)
10381000

10391001
# Normalize tools
1040-
normalized_tools: list[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any] = (
1041-
[] if tools_ is None else tools_ if isinstance(tools_, list) else [tools_]
1042-
)
1002+
normalized_tools = normalize_tools(tools_)
10431003
agent_name = self._get_agent_name()
10441004

10451005
# Resolve final tool list (runtime provided tools + local MCP server tools)
@@ -1345,12 +1305,7 @@ def __init__(
13451305
id: str | None = None,
13461306
name: str | None = None,
13471307
description: str | None = None,
1348-
tools: FunctionTool
1349-
| Callable[..., Any]
1350-
| MutableMapping[str, Any]
1351-
| Any
1352-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any] | Any]
1353-
| None = None,
1308+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
13541309
default_options: OptionsCoT | None = None,
13551310
context_providers: Sequence[BaseContextProvider] | None = None,
13561311
middleware: Sequence[MiddlewareTypes] | None = None,

python/packages/core/agent_framework/_clients.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Awaitable,
1010
Callable,
1111
Mapping,
12-
MutableMapping,
1312
Sequence,
1413
)
1514
from typing import (
@@ -31,7 +30,7 @@
3130
from ._serialization import SerializationMixin
3231
from ._tools import (
3332
FunctionInvocationConfiguration,
34-
FunctionTool,
33+
ToolTypes,
3534
)
3635
from ._types import (
3736
ChatResponse,
@@ -448,11 +447,7 @@ def as_agent(
448447
name: str | None = None,
449448
description: str | None = None,
450449
instructions: str | None = None,
451-
tools: FunctionTool
452-
| Callable[..., Any]
453-
| MutableMapping[str, Any]
454-
| Sequence[FunctionTool | Callable[..., Any] | MutableMapping[str, Any]]
455-
| None = None,
450+
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
456451
default_options: OptionsCoT | Mapping[str, Any] | None = None,
457452
context_providers: Sequence[Any] | None = None,
458453
middleware: Sequence[MiddlewareTypes] | None = None,

0 commit comments

Comments
 (0)