Skip to content

Commit 775b8fc

Browse files
Fix YAML agent ignoring model.options execution settings (#13365)
## Summary Fixes #13349 When loading agents from YAML files using `AgentRegistry.create_from_file()` or `create_from_yaml()`, the `model.options` field (containing settings like `response_format`, `temperature`, etc.) were being added as regular `KernelArguments` dict items instead of being placed in the `execution_settings` property. This caused AI service calls to ignore these critical settings. ## Root Cause In `_normalize_spec_fields()` method in `python/semantic_kernel/agents/agent.py`, model options were being passed to `KernelArguments` constructor as `**kwargs`: ```python # OLD (buggy) CODE arguments = KernelArguments(**model_options) ``` This made them regular dict items, but execution settings need to be in the `execution_settings` property to be passed to AI services. ## Changes Modified `_normalize_spec_fields()` in `python/semantic_kernel/agents/agent.py`: - Added import for `PromptExecutionSettings` - Convert model.options to `PromptExecutionSettings` object before creating `KernelArguments` - Model options now correctly placed in `execution_settings` property - Input defaults continue to be added as regular dict items (correct behavior) ## Testing - ✅ Created custom test verifying model.options are now in execution_settings - ✅ All 30 existing unit tests in `tests/unit/agents/test_agent.py` pass - ✅ No breaking changes introduced - ✅ Verified execution_settings passed programmatically still work correctly ## Example YAML file: ```yaml type: chat_completion_agent name: TestAgent description: Test agent instructions: You are a test agent model: options: response_format: structured_output temperature: 0.7 ``` **Before this fix:** - `response_format` was in dict items (wrong location) - AI service calls ignored it **After this fix:** - `response_format` is in `execution_settings.extension_data` - AI service calls receive it properly
1 parent 6888aa6 commit 775b8fc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

python/semantic_kernel/agents/agent.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pydantic import Field, model_validator
1414

1515
from semantic_kernel.agents.channels.agent_channel import AgentChannel
16+
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
1617
from semantic_kernel.contents.chat_message_content import CMC_ITEM_TYPES, ChatMessageContent
1718
from semantic_kernel.contents.streaming_chat_message_content import StreamingChatMessageContent
1819
from semantic_kernel.contents.utils.author_role import AuthorRole
@@ -998,9 +999,19 @@ def _normalize_spec_fields(
998999
if v.get("default") is not None
9991000
}
10001001

1001-
# Start with model options
1002-
arguments = KernelArguments(**model_options)
1003-
# Update with input defaults (only if not already provided by model options)
1002+
# Convert model options to execution settings
1003+
# Model options (like response_format, temperature, etc.) should be execution settings,
1004+
# not regular arguments
1005+
if model_options:
1006+
# Create PromptExecutionSettings from model options
1007+
# The PromptExecutionSettings constructor handles **kwargs by putting them in extension_data
1008+
# and then unpacking them to actual fields if they exist
1009+
exec_settings = PromptExecutionSettings(**model_options)
1010+
arguments = KernelArguments(settings=exec_settings)
1011+
else:
1012+
arguments = KernelArguments()
1013+
1014+
# Add input defaults as regular dict items (not execution settings)
10041015
for k, v in input_defaults.items():
10051016
if k not in arguments:
10061017
arguments[k] = v

0 commit comments

Comments
 (0)