Commit Graph
712 Commits
Author SHA1 Message Date
da8ca43064 Python: fix (openai): only propagate usage metadata for final streaming chunk without choices (#12977)
### Motivation and Context

1. Why is this change required?
- The previous condition copied usage metadata whenever chunk.usage
existed, which could incorrectly propagate usage into chunks that
already contained choices.

2. What problem does it solve?
- Prevents incorrect propagation of usage metadata that can cause empty
messages or duplicated metadata when a streaming chunk contains choices
plus usage.

3. What scenario does it contribute to?
- Streaming OpenAI chat responses where the API may send a final
usage-only chunk (no choices) to report usage stats.

4. If it fixes an open issue, please link to the issue here.
   - No linked issue.

### Description

- File modified:
-
python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion_base.py

- Change summary:
- In
OpenAIChatCompletionBase._inner_get_streaming_chat_message_contents,
    replace:
      if chunk.usage is not None
    with:
      if len(chunk.choices) == 0 and chunk.usage is not None

- Design notes:
- This is a minimal, targeted fix to ensure usage metadata is only
copied when the streaming chunk contains no choices (typical for the
final usage-only chunk).
  - Behavior of other streaming logic is unchanged.
  - Recommend adding unit tests covering:
- A chunk that contains choices and usage (should not propagate usage).
- A usage-only final chunk (should propagate usage to the synthesized
choice).

### Contribution Checklist

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the SK Contribution Guidelines and formatting
script raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

Files changed:
-
python/semantic_kernel/connectors/ai/open_ai/services/open_ai_chat_completion_base.py

---------

Co-authored-by: chentiantian <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>
2025-09-03 16:35:54 +00:00
Evan Mattson 4e9ea78390 Python: Bump Python version to 1.36.1 for a release (#13049)
### Motivation and Context

Bump Python version to 1.36.1 for a release

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.36.1 for a release

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-09-02 11:38:35 +09:00
Evan Mattson f7fdfcd9a9 Python: Add AzureAIAgent Deep Research Tool support (#13034)
### Motivation and Context

The deep research tool was introduced for the AzureAIAgent; however, we
didn't have support yet in SK. Adding support now for using the deep
research tool for both streaming and non-streaming. Samples added as
well.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Add support for deep research tool.
- Add samples with notes on prerequisites to configure the sample to run
properly.
- Added support for `AZURE_AI_AGENT_DEEP_RESEARCH_MODEL` env var within
`AzureAIAgentSettings` class.
- Bumped min allowed `azure-ai-agents` package ver to 1.2.0b3.
- Closes #12978

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-09-01 02:35:56 +00:00
Evan Mattson 86b10b95d2 Python: provide AzureAIAgent thread msg id during streaming (#13032)
### Motivation and Context

As part of invoking an AzureAIAgent via streaming, we weren't providing
the `thread_id` via the `AgentStreamEvent.THREAD_MESSAGE_CREATED` event.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Supply the caller with the `thread_msg_id` by sticking it into the
returned SCMC's `metadata` dictionary.
- Closes #12959

Sample output looks like:

```
Sample Output:

# User: 'Hello'
# AuthorRole.ASSISTANT: (thread message id: msg_HZ2h4Wzbj7GEcnVCjnyEuYWT) Hello! How can I assist you with 
    the menu today?
# User: 'What is the special soup?'
# AuthorRole.ASSISTANT: (thread message id: msg_TSjkJK6hHJojIkPvF6uUofHD) The special soup today is 
    Clam Chowder. Would you like to know more about it or anything else from the menu?
# User: 'How much does that cost?'
# AuthorRole.ASSISTANT: (thread message id: msg_liwTpBFrB9JpCM1oM9EXKiwq) The Clam Chowder costs $9.99. 
    Is there anything else you'd like to know?
# User: 'Thank you'
# AuthorRole.ASSISTANT: (thread message id: msg_K6lpR3gYIHethXq17T6gJcxi) You're welcome! 
    If you have any more questions or need assistance, feel free to ask. Enjoy your meal!
```

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-30 10:05:55 +00:00
5e50e190c4 Python: Add reasoning support for OpenAI Responses Agents (GPT-5, o4-mini, o3) (#12881)
## Summary

Adds reasoning capabilities to Python OpenAI ResponsesAgent, bringing
parity with the C# implementation. This enables fine-grained control
over reasoning effort for O-series models (o1, o3-mini, o4-mini) and
gpt-5 that support the reasoning parameter.

Fixes #12843

## Changes

### Core Implementation
- **`openai_responses_agent.py`**: Added reasoning configuration support
  - Constructor-level reasoning effort setting
  - Per-invocation reasoning effort override capability
  - Proper parameter validation and model compatibility checks
- **`responses_agent_thread_actions.py`**: Extended thread actions to
support reasoning parameters
  - Reasoning effort propagation through thread operations
  - Metadata preservation for reasoning tokens and summaries

### Sample and Tests
- **`responses_agent_reasoning.py`**: Comprehensive demonstration sample
  - Constructor vs per-invocation reasoning configuration
  - Function calling integration with reasoning
  - Reasoning comparison scenarios (low/medium/high effort)
  - Error handling and troubleshooting guidance
- **`test_openai_responses_agent_reasoning.py`**: Full unit test
coverage
  - Parameter validation tests
  - Integration scenarios with function calling
  - Edge cases and error conditions

## Features

✅ **Constructor-Level Reasoning**: Set default reasoning effort when
creating agents
✅ **Per-Invocation Override**: Override reasoning effort per request  
✅ **Priority Hierarchy**: per-invocation > constructor > model default  
✅ **Function Calling Compatible**: Works seamlessly with existing plugin
system
✅ **Azure OpenAI & OpenAI Support**: Compatible with both service
providers
✅ **Model Validation**: Automatic compatibility checks for O-series
models nad GÜT-5
✅ **Metadata Access**: Reasoning tokens and summaries available in
response metadata

## Usage Example

```python
# Constructor-level reasoning
# Constructor-level reasoning configuration
agent = AzureResponsesAgent(
    ai_model_id="gpt-5",
    client=client,
    reasoning={"effort": "low"}  # Default reasoning for all requests
)

# Per-invocation override
response = await agent.invoke(
    "Solve this complex problem step by step",
    reasoning={"effort": "high"}  
)


# Invoke with reasoning callback to capture intermediate thoughts
response = await agent.invoke(
    "Analyze this data step by step",
    reasoning={"effort": "high", "summary": "detailed"},
    on_intermediate_message=handle_reasoning_message
)

# Streaming with reasoning
async for response in agent.invoke_stream(
    "Explain quantum computing in detail",
    reasoning={"effort": "high", "summary": "detailed"},
    on_intermediate_message=handle_reasoning_message
):
    print(response.content, end="", flush=True)

---------

Co-authored-by: Evan Mattson <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>
2025-08-28 23:25:26 +00:00
ふぁーandEvan Mattson d3318adfc2 Python: Add container_id and filename fields to AnnotationContent class (#12985)
### Motivation and Context

I confirmed that Code Interpreter can run via Azure Responses API in
Semantic Kernel, but I found two issues: an error occurs when a file is
created inside the Code Interpreter, and the response lacks parameters
required to access the created file.

### Description

#### Bug 1: ValidationError for AnnotationContent

Semantic Kernel uses the following enum for
`AnnotationContent.content_type`:

```python
@experimental
class CitationType(str, Enum):
    """Citation type."""

    URL_CITATION = "url_citation"
    FILE_PATH = "file_path"
    FILE_CITATION = "file_citation"
```

However, the Responses API returns file citations with a `type` like
this:

```json
{"container_id": "cntr_68a6c50135d88190b6fdc062051155b50847ddec73d3be1b", "end_index": 94, "file_id": "cfile_68a6c67a7fcc8190889d7e1789d485e2", "filename": "sample.txt", "start_index": 66, "type": "container_file_citation"}
```

There is no matching enum member on the Semantic Kernel side. The
`CitationType` should include `CONTAINER_FILE_CITATION`, for example:

```python
@experimental
class CitationType(str, Enum):
    """Citation type."""

    URL_CITATION = "url_citation"
    FILE_PATH = "file_path"
    FILE_CITATION = "file_citation"
    CONTAINER_FILE_CITATION = "container_file_citation"
```

#### Bug 2: Missing parameters to access generated files

The response returned by the agent shows a `file_id`, but lacks the
`container_id` and `filename` required to download the file (the
filename is needed to replace `sandbox:/mnt/data/sample.txt`):

Example call:

```python
r = await agent.get_response(cast(list, history.messages), thread=thread)
print(r.content.items)
```

Example output:

```python
[
  TextContent(inner_content=None, ai_model_id=None, metadata={}, content_type='text', text='<user_prompt>', encoding=None),
  TextContent(inner_content=None, ai_model_id=None, metadata={}, content_type='text', text='<assistant_message>\n\n[sample.txt](sandbox:/mnt/data/sample.txt)', encoding=None), 
  AnnotationContent(inner_content=None, ai_model_id=None, metadata={}, content_type='annotation', file_id='cfile_68a6c67a7fcc8190889d7e1789d485e2', quote=None, start_index=88, end_index=116, url=None, title=None, citation_type=<CitationType.CONTAINER_FILE_CITATION: 'container_file_citation'>)
]
```

To include these values in the parsed result, `AnnotationContent` in
`semantic_kernel/contents/annotation_content.py` should expose
`container_id` and `filename`, and map the incoming `type` to
`citation_type`. Example suggested structure:

```python
@experimental
class AnnotationContent(KernelContent):
    """Annotation content."""

    content_type: Literal[ContentTypes.ANNOTATION_CONTENT] = Field(ANNOTATION_CONTENT_TAG, init=False)  # type: ignore
    tag: ClassVar[str] = ANNOTATION_CONTENT_TAG
    file_id: str | None = None
    quote: str | None = None
    start_index: int | None = None
    end_index: int | None = None
    url: str | None = None
    title: str | None = None
    # added
    container_id: str | None = None
    filename: str | None = None
    citation_type: CitationType | None = Field(None, alias="type")

    model_config = ConfigDict(
        extra="ignore",
        populate_by_name=True,
    )

    def __str__(self) -> str:
        ...

    def to_element(self) -> Element:
        ...

    @classmethod
    def from_element(cls: type[_T], element: Element) -> _T:
        ...

    def to_dict(self) -> dict[str, Any]:
        ...
```

Summary: add the missing enum value `container_file_citation` and extend
`AnnotationContent` to include `container_id` and `filename` (and map
`type` to `citation_type`) so file references returned by the Azure
Responses API are fully usable.

#### Code

```python
client: AsyncAzureOpenAI = AsyncAzureOpenAI(
    base_url=urljoin(server_settings.AZURE_OPENAI_COMPLETION_ENDPOINT.rstrip("/") + "/", "openai/v1/"),
    api_key=server_settings.AZURE_OPENAI_COMPLETION_API_KEY,
    api_version="preview",
)

async def run(history: ChatHistory) -> dict[str, Any]:
    with open("sample.txt", "rb") as fp:
        f = await client.files.create(file=fp, purpose="assistants")

    agent = AzureResponsesAgent(
        ai_model_id=server_settings.AZURE_OPENAI_COMPLETION_DEPLOYMENT_NAME,
        client=client,
        name="name",
        function_choice_behavior=FunctionChoiceBehavior.Required(),
        tools=[
            CodeInterpreter(
                type="code_interpreter",
                container=CodeInterpreterContainerCodeInterpreterToolAuto(type="auto", file_ids=[f.id]),
            )
        ],
    )

    thread = ResponsesAgentThread(client, history, previous_response_id=None, enable_store=True)
    r = await agent.get_response(cast(list, history.messages), thread=thread)
    print(thread.id, r.content.items)

    annotation_content = [item for item in r.content.items if isinstance(item, AnnotationContent)]

    for ac in annotation_content:
        print(ac.file_id, ac.filename, ac.container_id)
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

Co-authored-by: Evan Mattson <[email protected]>
2025-08-28 00:01:39 +00:00
Evan Mattson 1179122a5e Python: Bump Python version to 1.36.0 for a release. (#13014)
### Motivation and Context

Bump Python version to 1.36.0 for a release.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.36.0 for a release.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-26 22:09:17 -07:00
Dmytro Struk 18d9a8e8b2 Python: .Net: Updated encoding logic in prompt templates (#12983)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves: https://github.com/microsoft/semantic-kernel/issues/11821

Today, the encoding of template arguments is performed only if argument
type is `string`. In case of custom type, anonymous type or collection -
the encoding is not performed.

This PR contains changes to throw an exception in case if encoding is
enabled but complex type is used. In case of complex type, the encoding
should be performed manually according to business logic and automatic
encoding should be explicitly disabled.

This enforces stricter, but more secure template rendering rules.

**Note**: this is a breaking change for customers who use Handlebars or
Liquid template with complex type arguments. Code changes are required
when initializing template arguments:
```diff
var arguments = new KernelArguments()
{
    { "customer", new
        {
-             firstName = userInput.FirstName,
-             lastName = userInput.LastName,
+             firstName = HttpUtility.HtmlEncode(userInput.FirstName),
+             lastName = HttpUtility.HtmlEncode(userInput.LastName),
        }
    }
};

var templateFactory = new LiquidPromptTemplateFactory();
var promptTemplateConfig = new PromptTemplateConfig()
{
    TemplateFormat = "liquid"
+   InputVariables = new()
+   {
+       // We set AllowDangerouslySetContent to 'true' because each property of this argument is encoded manually. 
+       new() { Name = "customer", AllowDangerouslySetContent = true },
+   }
};

var promptTemplate = templateFactory.Create(promptTemplateConfig);
var renderedPrompt = await promptTemplate.RenderAsync(kernel, arguments); 
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2025-08-26 22:09:00 -07:00
Dmytro Struk 2a47ba9b7d Python: Removed usage of DefaultAzureCredential (#12964)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

The usage of `DefaultAzureCredential` by default is unsafe and raises
security issues. Instead, users should provide their own credential
types such as `AzureCliCredential`, `ManagedIdentityCredential` and so
on. More information here:

https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.aio?view=azure-python

In this PR:
1. Removed the usage of `DefaultAzureCredential` from authentication
logic.
2. Replaced `DefaultAzureCredential` with `AzureCliCredential` in all
examples.

**Note**: this is breaking change for Azure users, who relies on
`DefaultAzureCredential`. Users will need to update the code and pass
the credential type of their choice by using `credential` parameter when
initializing one of the Azure clients.

Before:
```python
chat_completion = AzureChatCompletion()
```

After:
```python
chat_completion = AzureChatCompletion(credential=AzureCliCredential())
```

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2025-08-25 18:29:13 +00:00
45fe60545c Python: Fix issue with orphaned tool/tool_calls (#12923)
### Motivation and Context

Tool/tool_calls are getting orphaned.

Issue : https://github.com/microsoft/semantic-kernel/issues/12708

How to reproduce :

```python
from semantic_kernel.contents import (
    AuthorRole,
    ChatMessageContent,
    FunctionCallContent,
    FunctionResultContent,
    ChatHistoryTruncationReducer,
)

messages = [
    ChatMessageContent(role=AuthorRole.SYSTEM, content="sys"),
    ChatMessageContent(role=AuthorRole.USER, content="user A"),
    ChatMessageContent(
        role=AuthorRole.ASSISTANT,
        items=[
            FunctionCallContent(
                id="123", function_name="search", plugin_name="plugin", arguments={"q": "x"}
            )
        ],
    ),
    ChatMessageContent(
        role=AuthorRole.TOOL,
        items=[
            FunctionResultContent(
                id="123", function_name="search", plugin_name="plugin", result="RESULT"
            )
        ],
    ),
    ChatMessageContent(role=AuthorRole.USER, content="user B"),
    ChatMessageContent(role=AuthorRole.ASSISTANT, content="done"),
]

reducer = ChatHistoryTruncationReducer(target_count=3, threshold_count=0)
reducer.messages = messages

print("Before reduce:", [m.role for m in reducer.messages])
await reducer.reduce()
print("After reduce:", [m.role for m in reducer.messages])

# After reduce: [<AuthorRole.TOOL: 'tool'>, <AuthorRole.USER: 'user'>, <AuthorRole.ASSISTANT: 'assistant'>]
```

### Description

Move backward as long as we are in a tool/tool_call island when reducing
the messages.

---------

Co-authored-by: Allaoua Benchikh <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>
2025-08-14 00:23:04 +00:00
Evan Mattson 09fb007bb1 Python: Bump Python version to 1.35.3 for a release (#12945)
### Motivation and Context

Bump Python version to 1.35.3 for a release

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.35.3 for a release

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-14 09:17:46 +09:00
Tao Chen 6416c58b90 Python: Add arguments and results attributes to execute tool span (#12940)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
We are adding two new attributes to the execute tool span according to
this proposal to Otel Semantic Conventions:
https://github.com/open-telemetry/semantic-conventions/pull/2528

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
The following two attributes are added to the `execute_tool` span:
1. `gen_ai.tool.call.arguments`
2. `gen_ai.tool.call.result`

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-08-13 23:35:42 +00:00
Evan Mattson 40734345dc Python: Fix the Responses agent msg chaining with reasoning models (#12907)
### Motivation and Context

When running a reasoning model with the OpenAI responses agent, it was
producing 400s due to the way we were either including or not including
FCC related to tool calls. This PR fixes it for both the default
(store_enabled=True) and the case where uses don't want to use OpenAI's
previous response id as a pseudo-thread (store_enabled=False).

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Closes #12843

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-13 10:35:38 +00:00
Evan Mattson d4e0278330 Python: Bump Python version to 1.35.2 for a release (#12894)
### Motivation and Context

Bump Python version to 1.35.2 for a release

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.35.2 for a release

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-08 01:14:45 +00:00
Mehdi MoshtaghiandEvan Mattson 73ad6e8923 Python: Fix: Implement __deepcopy__ on KernelFunction to handle non-serializable OTEL metrics (#12803)
### Description

This PR fixes TypeError: cannot pickle '_thread.RLock' object which
occurs when kernel.clone() is called while OpenTelemetry metrics are
enabled.

-   Fixes: #12802

### Motivation and Context

When using features like `HandoffOrchestration`, the agent's `Kernel` is
cloned. This process uses `copy.deepcopy`, which fails on the
`KernelFunction`'s OpenTelemetry `Histogram` fields
(`invocation_duration_histogram` and `streaming_duration_histogram`).
These histogram objects contain thread locks, making them
non-serializable.

Previous solutions, like the one in **PR #9292**, used
`Field(exclude=True, default_factory=...)`. While that was a necessary
step, it was insufficient because `deepcopy` does not respect the
`exclude` flag in the same way that Pydantic's serialization does. This
bug blocks the use of certain agentic features in any application that
has metrics-based observability enabled.

### Description of the change

This solution introduces a custom __deepcopy__ method to the
KernelFunction Pydantic model. This method correctly handles the
deep-copying process for KernelFunction instances:

1.  It intercepts the deepcopy call for KernelFunction objects.
2. It uses self.model_copy(deep=False) to create a new instance of the
Pydantic model. Using deep=False allows the default_factory for the
histogram fields to create new, clean instances on the copied object,
while other fields are shallow-copied.
3. It then manually deep-copies all other attributes from the original
object to the new one, ensuring that any other mutable objects (like
metadata`) are correctly duplicated. The histogram fields are explicitly
skipped in this step, as they have already been recreated by
`model_copy.
4. Standard deepcopy memoization is used to prevent infinite recursion
in the case of cyclic object graphs.

This approach ensures that the non-serializable fields are
re-initialized instead of copied, resolving the TypeError while
maintaining the integrity of the cloned object.

### How has this been tested?

The fix was validated using the reproduction steps outlined in the
associated issue. Running an agent orchestration that triggers
kernel.clone() with OpenTelemetry metrics enabled now completes
successfully without any errors.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <[email protected]>
2025-08-07 22:48:43 +00:00
Eduard van Valkenburg a6b5f34d9b Python: fix parsing of types in mcp server (#12871)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
The parsing of tool call output was not working correctly, this fixes
that.
Solves #12850 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-08-07 21:49:37 +00:00
Evan Mattson 91392a77e0 Python: Fix ResponsesAgent image duplication in chat history preparation (#12859)
### Motivation and Context

The ResponsesAgent is duplicating messages in chat history preparation
when messages contained multiple content items (text + images). The
`response_inputs.append()` call is inside the content processing loop,
causing each message to be added once per content item.

The fix:
- Moved `response_inputs.append()` outside the content processing loop
- Added unit test to verify multiple images don't get duplicated

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Fixed loop placement in `_prepare_chat_history_for_request`
- Added test `test_prepare_chat_history_multiple_images_no_duplication`
- Fixes #12848

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-05 14:58:35 +00:00
Evan Mattson 58c3c4d27f Python: Bump Python version to 1.35.1 for a release. (#12856)
### Motivation and Context

Bump Python version to 1.35.1 for a release.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.35.1 for a release.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-05 11:09:38 +09:00
Tao ChenandDmytro Struk 8336c320d9 Python: Add bedrock model provider parameter (#12853)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Fixes #12833 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Add an optional setting to the Bedrock AI connectors to allow users to
specify the Bedrock model providers (i.e. amazon, anthropic, etc) so
that they can use application inference profiles.


### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Dmytro Struk <[email protected]>
2025-08-05 00:43:00 +00:00
Evan Mattson 1198b573d1 Python: Add ability to specify encoding when adding a plugin. Add tests. (#12797)
### Motivation and Context

Right now when adding a plugin, we don't allow one to specify the type
of encoding used.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Allow configuration for the type of encoding used.
- Adds unit tests
- Closes #12440

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-04 22:00:30 +00:00
Evan Mattson e5972e2430 Python: Add incomplete details reason to AzureAIAgent error message (#12796)
### Motivation and Context

When errors occur processing a run of an AzureAIAgent, we surface the
error message but not the incomplete_details reason if it exists.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

This PR adds handling for the incomplete details reason, if it exists,
so it can be passed back via the error message.
- Closes #12752

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-08-04 21:59:19 +00:00
Tao ChenandEvan Mattson b7bb2832aa Python: Input & output attributes in invoke_agent span (#12834)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
The OTel workgroup has been thinking about enhancing tracing for agents.
This is a proposal from our tracing team:
https://github.com/open-telemetry/semantic-conventions/pull/2528. This
PR implements part of the proposal so that when the proposal gets
merged, we can quickly follow.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Two new attributes are added to the `invoke_agent` span, namely the
`gen_ai.agent.invocation_input` and `gen_ai.agent.invocation_output`.

<img width="747" height="583" alt="image"
src="https://github.com/user-attachments/assets/d8b81f68-915b-48ee-8f86-66a0d4f686cc"
/>


### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <[email protected]>
2025-08-04 21:54:45 +00:00
Tao ChenandChris 358b0f343b Python: .Net: Magentic orchestration to return the last agent message when limits reached (#12839)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Related to #12687
Related to #12656 

Currently, the Magentic orchestration returns a static message if the
max reset limit or the max invocation limit is reached.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Return the last agent response if either of the limit is reached.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Chris <[email protected]>
2025-08-04 18:17:44 +00:00
Evan Mattson 1efc7ad04e Python: Pass through arguments when creating agents from specs (#12771)
### Motivation and Context

Currently, attempting to pass through KernelArguments through agent
creation via declarative spec isn't working properly. The arguments are
used to normalize fields, but are then not passed through fully to where
the agent is created.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Pass arguments through, and merge them properly with the normalized
fields. This allows for underlying args to be used by the agent, like in
the case of structured outputs.
- Closes #12770

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-24 05:47:43 +00:00
Evan Mattson 5332c2e330 Python: Require tool_call_id parameter for string-based tool messages in ChatHistory (#12753)
### Motivation and Context

The `add_tool_message` method of `ChatHistory` accepts string content
without requiring a `tool_call_id` parameter. This design is flawed from
an API design perspective. It created tool messages that:

1. Violated chat completion protocols: most LLM APIs (OpenAI, etc.)
require tool messages to have a `tool_call_id` that references a
previous function call
2. Broke conversation flow: tool messages should always be responses to
specific tool calls, maintaining the call-response relationship
3. Created malformed message sequences: messages without proper tool
call IDs would fail when sent to language models

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

This PR modifies the `add_tool_message` string overload to require a
`tool_call_id` parameter, which makes sure we have proper tool call
protocol compliance.

1. The string overload now validates that `tool_call_id` is provided and
raises a clear error if missing
2. Tool messages now create `FunctionResultContent` objects with both
`id` and `call_id` set to the provided `tool_call_id`
3. Added support for an optional `function_name` parameter for better
bookkeeping
4. Provides informative error messages explaining why `tool_call_id` is
required
- Closes #12744 

Before:

```python
# This would create an invalid tool message without tool_call_id
# when the `.to_dict()` method is called on `ChatMessageContent`
chat_history.add_tool_message("Function result")  # Creates broken message and losing pairing to the corresponding `FunctionCallContent`.
```

After: 

```python
# Now requires tool_call_id for proper protocol compliance
chat_history.add_tool_message("Function result")  # raises clear error due to missing `tool_call_id`
chat_history.add_tool_message("Function result", tool_call_id="call_123")  # works correctly

# Optional function name for better bookkeeping
chat_history.add_tool_message("Function result", tool_call_id="call_123", function_name="get_weather") # works as well
```

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-23 04:07:20 +00:00
Evan Mattson d4f6703cf3 Python: fix Bing grounding & custom search content generation (#12760)
### Motivation and Context

The same `agent_content_generation` method is used to handle both
`bing_grounding` and `bing_custom_search` tool calls; however, the
method expected that the dicts on the underlying types were named the
same - which they aren't. They have their respective names, as shown
above.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Fix Bing content generation based on the instance we're dealing with.
- Add unit tests.
- Closes #12746

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-23 03:17:29 +00:00
Tao Chen b723fbd5e1 Python: Add mix agent orchestration sample (#12749)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
We don't have a sample showing how to use a mix of agents of various
types in an orchestration. This PR adds one.
A bug is also discovered in the OpenAIResponsesAgent while creating the
sample.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Add a new sample showing how to use a mix of agents in the Handoff
orchestration.
2. Fix a bug in the OpenAIResponsesAgent where the tools were not
considering the tools in the kernel instance. A new test is added too.
3. Fix a bug in the AgentActorBase where the intermediate message
callback was rejecting ChatMeesageContent type.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-07-22 16:57:05 +00:00
Eduard van Valkenburg c79f5a5c63 Python: improved MCP connect and additional samples (#12696)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Adding a sample using StreamableHTTPServer towards Github.
Added a demo showing how to connect to a OAuth protected MCP server.
Also some improvements in the connect logic for MCP.


### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-07-22 15:14:32 +00:00
Evan Mattson 48f71b1f2e Python: Support AzureAI agent MCP tools for streaming and non-streaming invocations (#12736)
### Motivation and Context

MCP tool support was released for the AzureAI Agent and it has yet to be
added to the SK Python AzureAIAgent. This PR adds functionality to
handle the MCP tools for both streaming and non-streaming invocations.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Adds MCP support for the Python AzureAI Agent.
- Upgrades dependent packages to be able to use the mcp tool from the
Azure SDK.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-18 07:08:00 +00:00
Evan Mattson 190954a2c9 Python: Bump Python version to 1.35.0 for a release (#12725)
### Motivation and Context

Bump Python version to 1.35.0 for a release

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.35.0 for a release

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-16 08:19:31 +09:00
Tao Chen b74ea05540 Python: Improve orchestration exception handling (#12716)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Currently, exceptions that occur inside the orchestration actors are not
properly surfaced to the caller as it happens.

Fixes: https://github.com/microsoft/semantic-kernel/issues/12719

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
This PR addresses the issue by introducing a new exception_callback that
is hidden from the user but will raise exceptions that occurs inside the
orchestration actors to the caller.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-07-15 23:03:22 +00:00
Evan Mattson ba031e689d Python: Properly handle AzureAI Search results for AzureAIAgent (#12654)
### Motivation and Context

After the Azure AI Agent service went to GA, there were some updates in
the underlying SDK. When there are azure_ai_search results while running
the agent, they no longer show up as attributes related to the tool
call. They are present in the dictionary, so our current code is failing
when trying to access the attribute. This PR updates how we form the
FunctionCallContent or FunctionResultContent for both azure_ai_search
streaming and non-streaming.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Update how we form the FunctionCallContent or FunctionResultContent for
both azure_ai_search streaming and non-streaming for the AzureAIAgent.
- Closes #12422

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-08 01:53:17 +00:00
ふぁー 93a14d5115 Python: feature: support gpt-image-1 (#12621)
This pull request was created in response to the issue
https://github.com/microsoft/semantic-kernel/issues/12500#issuecomment-2998387488.
The current AzureTextToImage implementation only works with DALL-E 3.
For gpt-image-1, the response format has changed from a URL to base64
only, which the current code does not support.

Additionally, gpt-image-1 introduces a new image editing feature that
also needs to be supported. Since breaking changes are required, new
methods have been added.

Minimal code that reproduces the problem
```python
service = AzureTextToImage(
        service_id=service_id,
        deployment_name="image-1",
        endpoint=AZURE_OPENAI_IMAGE_ENDPOINT,
        api_key=AZURE_OPENAI_IMAGE_API_KEY,
    )
)

settings = service.get_prompt_execution_settings_class()(service_id="image1")
settings.prompt = "sky"
settings.size = ImageSize(width=1024, height=1024)
settings.quality = "low"
r = await service.generate_image(settings=settings)
```

Example of use with newly added methods
```python
from semantic_kernel.connectors.ai.open_ai import AzureTextToImage
service = AzureTextToImage(
    service_id="image1",
    deployment_name="gpt-image-1",
    endpoint=AZURE_OPENAI_IMAGE_ENDPOINT,
    api_key=AZURE_OPENAI_IMAGE_API_KEY,
    api_version="2025-04-01-preview",
)
settings = service.get_prompt_execution_settings_class()(service_id="image1")
settings.n = 3
images_b64 = await service.generate_images("A cute cat wearing a whimsical striped hat", settings=settings)
```

```python
  from semantic_kernel.connectors.ai.open_ai import AzureTextToImage
  service = AzureTextToImage(
      service_id="image1",
      deployment_name="gpt-image-1",
      endpoint=AZURE_OPENAI_IMAGE_ENDPOINT,
      api_key=AZURE_OPENAI_IMAGE_API_KEY,
      api_version="2025-04-01-preview",
  )
  file_paths = ["./new_images/img_1.png", "./new_images/img_2.png"]
  settings = service.get_prompt_execution_settings_class()(service_id="image1")
  settings.n = 2
  results = await service.edit_image(
      prompt="Make the cat wear a wizard hat",
      image_paths=file_paths,
      settings=settings,
  )
```

## Problems Identified
1. Assumption of URL-based responses. The current implementation assumes
a response format that includes an image url, which is not the case for
gpt-image-1. See:
https://github.com/microsoft/semantic-kernel/blob/8d1b3fd55155bb65e9671383366d2672c4582fb0/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py#L69
2025-07-04 14:11:56 +00:00
Evan Mattson c15c885f84 Python: Emit partial result for magentic pattern when retrieving final result, if available (#12656)
### Motivation and Context

When using the magentic orchestration pattern, if the `max_round_count`
is hit, the final result shows as:

```
Final result:
Max round count reached.
```

The interim messages do show as part of the `agent_response_callback`;
however, not everyone may have that configured. We should return more
meaningful results, even if partial. This PR updates to try and get a
partial result if it exists. When one calls:

```python
value = await orchestration_result.get()
```

for the `step5_magentic.py` sample, with `max_round_count=1` they should
receive the partial result:

```
Final result:
Based on the available data, here is a comparison of the estimated training and inference energy consumption for ResNet-50, BERT-base, and GPT-2, along with the associated CO₂ emissions when training on an Azure Standard_NC6s_v3 VM for 24 hours.

**Model Architectures and Datasets:**

- **ResNet-50**: Image classification model trained on ImageNet.
- **BERT-base**: Text classification model fine-tuned on the GLUE benchmark.
- **GPT-2**: Text generation model trained on WebText.

... <rest omitted for brevity> ...
```

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Return partial results for magentic orchestration if they exist.
- Closes #12625

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-07-02 15:18:27 +00:00
Tao Chen ba000c3368 Python: Use message cache in agent orchestrations (#12618)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Some agent threads don't support adding messages. An example of this is
the copilot studio agent.

In an agent orchestration, an agent may receive multiple messages before
it is asked to generate a response. The currently approach in the
orchestrations would add new messages to an agent thread whenever an
agent receives a message, making the copilot studio agent not compatible
with some orchestrations.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
Instead of adding messages to the agent thread, this PR introduces a
message cache to store messages temporarily before the agent is invoked.


### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-07-01 19:00:05 +00:00
Evan Mattson ef392d22ee Python: Bump version to 1.34.0 for a release (#12580)
### Motivation and Context

Bump version to 1.34.0 for a release.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump version to 1.34.0 for a release.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-25 09:16:33 +09:00
sshandilya1991 16d708e161 Python: added operationid validation in openapi spec (#12551)
Description
This PR enforces the presence of an explicit `operationId` for every
operation in the OpenAPI specification. Previously, if `operationId` was
missing, a default value was generated using the path and HTTP method.
Now, the parser will raise a PluginInitializationError if operationId is
not provided, ensuring that all operations are uniquely and explicitly
identified as required by the OpenAPI standard.

Key changes:

- Added validation to check for the existence of operationId in each
operation.
- If operationId is missing, a clear error is raised, preventing
fallback to a default value.
-
[python/tests/unit/connectors/openapi_plugin/no-operationid-openapi.yaml](https://github.com/microsoft/semantic-kernel/compare/main...sshandilya1991:semantic-kernel:sshandilya/12443_add_operation_id_validation?expand=1#diff-3d272039b3afa97f89805f0ee0258a98b613f0f373c603467b336a8912d5651a)
serves as a test case.
- Closes #12443

Edit:
- Added more validation for operationId to be unique & throw in case
duplicate operationId found while parsing.
2025-06-24 06:36:02 +00:00
Evan Mattson 2bfa31b754 Python: pseudo-stream copilot invoke_stream (#12548)
### Motivation and Context

The current copilot studio client doesn't support streaming invocation.
The underlying orchestration patterns rely on agents to have an
invoke_stream. Since it doesn't exist in the copilot agent, that agent
type cannot be used. This PR implements a pseudo-invoke_stream so that
the agent can be used with patterns - although it doesn't stream the
response back in chunks, it unblocks the use if one desired to use our
new orchestration patterns.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Closes #12449

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-20 15:21:43 +00:00
Evan Mattson 9e3cdffc6b Python: Improve AzureAIAgent get thread msg handling. (#12535)
### Motivation and Context

Currently, when fetching thread messages for an AzureAIAgent, it assumes
that the agent exists, so we can pull it down and get its id. This may
not always be the case - an agent could have been deleted, but the
thread still exists. We need to account for this.

When creating user messages that we add to the thread, there's no `name`
or `id` parameter allowed. We can, however, add metadata to the message.
Going forward we are adding the `agent_id` as metadata to the message,
so upon retrieval later, we can attempt to get it and return the id with
the user's message. This allows one to see which agent_id has responded
to the user's message:

```
# Messages in the thread (asc order):

# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: Hello
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: Hello! How can I assist you with the menu today?
# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: What is the special soup?
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: The special soup today is Clam Chowder. Would you like to know more about it or anything else on the menu?
# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: How much does that cost?
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: The Clam Chowder costs $9.99. Would you like to order it or need information on other items?
# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: Thank you
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: You're welcome! If you have any more questions or need assistance with the menu, feel free to ask. Enjoy your meal!
```

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Closes #12435

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-19 23:52:07 +00:00
Eduard van Valkenburg 003cc4c010 Python: Feature python vector stores preb (#12271)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Overhaul of the VectorStores to get it matching with dotnet and the
latest development there.

Closes: 
- #11938 
- #11598 
- #11597
- #11517 
- #10561 
- #10391 
- #9911 
- #9892 
- #10867 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

Many changes, some highlights:
- Moved from different vector fields types, to a single with a enum
first VectorStoreField()
- Renamed several items
- Made embeddinggenerrator a part of the vector field spec and do
automatic vectorization from there or from the same param on a
collection
- Adds hybrid search using the same setup
- Removed the intermediate TextSeachVectorSearch object need, by
allowing `create_search_function` directly on a collection

Will write out full changes in a migration guide in the docs.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2025-06-19 18:34:59 +00:00
Evan Mattson 466a610727 Python: Allow for structured outputs with Ollama (#12533)
### Motivation and Context

Ollama's execution settings currently only allow for `json` literal. We
also want to support structured outputs for models that support it.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Closes #12355
- Supersedes #12386

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-19 15:22:40 +00:00
kanchi cef5ae7402 Python: Support | and |= operators for KernelArgument (#12499)
### Motivation and Context

`KernelArguments` extends the built-in `dict` by adding an
`execution_settings` attribute.
However, when using the `|` and `|=` operators, only the `dict` part
(excluding `execution_settings`) is merged, and the result becomes a
plain `dict`.
This causes the `execution_settings` attribute to be lost and not
updated.

### Description

- Implemented support for the `|` and `|=` operators to make it easier
for users to merge `KernelArgument` objects.
- The right-hand or left-hand side of the operator can be either a
`KernelArgument` or a `dict` (or any subclass of dict).
- When merging, both the `execution_settings` attribute and the rest of
the `dict` data are merged individually, and the result is returned as a
`KernelArgument`.
- As long as either side of the operator is a `KernelArgument`, the
result will also be a `KernelArgument`.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-06-19 07:24:16 +00:00
Tao Chen 44f1253460 Python: Agent response callbacks to provide full context (#12501)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Currently, the agent response callbacks in the `Orchestrations` are
triggered only when the final responses from the agents become
available. This limits developers to create solutions that can expose
the internal processing of the agents in multi agent orchestrations.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
The callbacks will now be triggered by the intermediate messages of the
agents:
1. A new sample
2. Tests

P.s. Fix a bug where the name of the intermediate messages is not
assigned.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-06-17 16:17:11 +00:00
Eduard van Valkenburg 8d1b3fd551 Python: fixes for new MCP types and small openapi fix (#12486)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Fixes to include AudioContent for MCP
Small typing improvement in OpenAPI.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-06-16 21:32:42 +00:00
Tao Chen dfbc993d8f Python: Remove orchestration persona adaptation messages (#12446)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
We previously found that agents might get carried away from in long
contexts. The persona adaptation messages were designed to steer the
agents in an orchestration to respond more closely to the instructions
provided (as system message).

As we perform more testing with newer models, we believe that the
persona adaptation messages are no longer necessary. The additional
instability (because they are hardcoded messages that devs can't
override) and cost (the additional token cost which is not significant,
but they do pollute the context which makes debugging difficult) they
introduce is not worth the benefit they provide.


Closing #12294 


> Ideally, we'd want to approach this more analytically. The lack of a
multi-agent evaluation process makes it difficult. All samples were
verified to make sure they behave the same before and after the removal
of the persona adaptation messages.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Remove the persona adaptation messages.
2. Unit tests.
3. Replace `OpenAIChatCompletion` with `AzureChatCompletion` in some of
the samples.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-06-11 15:58:21 +00:00
Evan Mattson 029732dc36 Python: Bump Python version to 1.33.0 for release (#12427)
### Motivation and Context

Bump Python version to 1.33.0 for release

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Bump Python version to 1.33.0 for release

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-10 09:00:08 +09:00
Evan Mattson 4b23389f71 Python: Emit token usage with streaming chat completion agent. (#12416)
### Motivation and Context

The chat completion agent was not emitting token using during streaming
invocation because we were only allowing through `response.items`. In
the case of token usage, `response.items` is [] and the usage is
contained as part of the message's `metadata` dict. This PR fixes that
bug and allows for `response.items or response.metadata.get("usage")`.
Two new samples are added to the concepts/agents/chat_completion dir to
show how one can track token use for streaming and non-streaming agent
invocation. Token usage handling is also added to the chat completion
agent integration tests.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Fixes a bug where we weren't emitting the streaming token usage for
the chat completion agent. Also now includes the `prompt_tokens_details`
and `completion_tokens_details` models that are returned, but not
previously handled.
- Adds new samples
- Updates integration tests to track token usage and make sure they're
non-zero.
- Closes #12411

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-09 23:12:05 +00:00
Evan Mattson c3c8dfabc6 Python: Bing custom search tool content support (#12415)
### Motivation and Context

In the `azure-ai-agent` package version 1.1.0b1, they provided the
`AgentsNamedToolChoiceType.BING_CUSTOM_SEARCH` enum. Adding this to then
provide support for generating bing grounding content for
streaming/non-streaming path.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Add BING_CUSTOM_SEARCH enum to allow for content support.
- Bumps `pyproject.toml` `azure-ai-agents` min allowed version to
`1.1.0b1` which includes this new enum.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
2025-06-09 23:10:44 +00:00
Evan Mattson 3e31c3bdc6 Python: Remove planner-related code and samples. (#12417)
### Motivation and Context

Per deprecation method, removing planner-related code after June 1,
2025.

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Removing planner-related code.
- Closes #12400

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
2025-06-09 21:35:23 +00:00
Tao Chen a7eab4ac6d Python: Remove model info check in Bedrock connectors (#12395)
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Closing #10941 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
To support more ways (via `model_id`, `inference_profile`, or `model
arn`) to send requests to Bedrock models, we have removed the checks on
whether a model supports certain features, i.e. streaming and embedding
generation. This is because to check for if a model support certain
features, we need the model id, but given the flexibility in specifying
the target model, it's no longer possible to retrieve the model
information realiably.


### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
2025-06-09 21:16:39 +00:00