Python: Empty tool results lose correlation and fail serialization
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 88/100
Línea de trabajo
Empieza en semantic_kernel/contents/chat_history.py, en ChatHistory._prepare_for_add(), y reproduce después el caso de resultado vacío del issue. Añade una regresión específica que cubra los campos de FunctionResultContent y message.to_dict(); se considera terminado cuando un resultado vacío de una herramienta conserva su ID de llamada y se serializa sin lanzar una excepción.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
ChatHistory.add_tool_message() drops an empty-string tool result instead of preserving it as FunctionResultContent. The appended message still has role tool, but its items list is empty and the supplied tool_call_id is lost. Serializing that otherwise ordinary history message then raises IndexError because ChatMessageContent.to_dict() expects a tool message to contain a function result.
An empty string is a valid tool result for cases such as a successful command with no stdout or a no-op tool. The helper documents content as a string and requires tool_call_id; it should retain both even when the string is empty.
To reproduce
from semantic_kernel.contents.chat_history import ChatHistory
history = ChatHistory()
history.add_tool_message("", tool_call_id="call_123")
message = history.messages[-1]
print(message.role.value, len(message.items))
print(message.to_dict())
On current main (3438d882):
tool 0
IndexError: list index out of range
No model, provider, credentials, or network request is involved.
Root cause and proposed scope
ChatHistory._prepare_for_add() currently constructs FunctionResultContent only when content is truthy:
if role == AuthorRole.TOOL and content and not items:
Changing that predicate to content is not None preserves the existing behavior while allowing a valid empty result to retain result="", id, and call_id. A focused regression should assert both the FunctionResultContent fields and the serialized tool-message dictionary.
This is related to, but distinct from, #13678: that PR improves an Azure adapter's error for manually constructed tool messages with no items. This issue is about preventing the public ChatHistory.add_tool_message() helper from creating that invalid shape when its documented string input is empty.
Expected behavior
The helper should append one FunctionResultContent with the empty result and supplied call ID, and message.to_dict() should produce a valid tool message instead of raising.
Platform
- Language: Python
- Source: current repository
mainat3438d882 - AI model: not applicable
- OS: macOS; provider-free reproduction
I can submit the focused predicate change and regression once maintainers confirm this contract.
- Lenguaje dominante
- C#
- Estrellas
- 28.6k
- Forks
- 4.8k
- Merge medio
- 13 h 24 min
- PR fusionados (30 d)
- 11
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/semantic-kernel
-
python triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
microsoft/semantic-kernel#14491 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
python triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/semantic-kernel#14490 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Python: [Python] structured_outputs_transform reuses ChatHistory across calls (prompt pollution)Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
microsoft/semantic-kernel#14483 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
.NET python triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
microsoft/semantic-kernel#14482 · 3 comentarios ·
Los mantenedores suelen responder en 2 días
-
Python: [Python] as_agent_framework_tool drops parameter defaults (optionals become required)Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
microsoft/semantic-kernel#14481 ·
Los mantenedores suelen responder en 2 días
Todos los issues de microsoft/semantic-kernel
Issues similares
-
go 🏃 testing 🧪
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
valkey-io/valkey-glide#7239 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
SubtitleEdit/subtitleedit#15462 ·
Los mantenedores suelen responder en 1 día
-
:watch: Not Triaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
comp:instrumentation.aspnetcore
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
open-telemetry/opentelemetry-dotnet-contrib#5427 ·
Los mantenedores suelen responder en 1 día
-
[feature request] Condier making `TelemetrySpan`'s constructor and `Activity` property publicAbiertoenhancement needs-triage pkg:OpenTelemetry
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
open-telemetry/opentelemetry-dotnet#7851 · 4 comentarios ·
Los mantenedores suelen responder en 1 día