strong-ice-84145
10/31/2025, 2:09 PMObservation class to make sure tools are consistent with error handling and llm serialization.
Unfortunately this PR changes lots of files. If this PR is too big to merge before a release, I can break it into pieces, or wait until after the release.
Proposed Observation structure:
class Observation(Schema, ABC):
"""Base schema for output observation."""
output: list[TextContent | ImageContent] = Field(
default_factory=list,
description=(
"Output returned from the tool converted to LLM Ready "
"TextContent or ImageContent"
),
)
error: str | None = Field(
default=None, description="Error message if operation failed"
)
@property
def command(self) -> str | None:
"""
The command that was executed to produce this observation.
Subclasses can override to provide the actual command run.
"""
return None
@property
def has_error(self) -> bool:
"""
Check if the observation indicates an error.
"""
return bool(self.error)
@property
def result_status(self) -> ObservationStatus:
"""
Get the observation result status based on presence of error."""
return ObservationStatus.ERROR if self.has_error else ObservationStatus.SUCCESS
def format_error(self) -> TextContent:
"""Format the error message for LLM display."""
return TextContent(text=f"Tool Execution Error: {self.error}")
@property
def to_llm_content(self) -> Sequence[TextContent | ImageContent]:
"""
Default content formatting for converting observation to LLM readable content.
Subclasses can override to provide richer content (e.g., images, diffs).
Errors can be partial so both output and error are included if present.
"""
llm_content: list[TextContent | ImageContent] = []
if self.command:
llm_content.append(TextContent(text=f"Executed Command: {self.command}\n"))
if self.error:
llm_content.append(self.format_error())
if self.output:
llm_content.extend(self.output)
return llm_contentcalm-artist-7206
10/31/2025, 2:46 PMstrong-ice-84145
10/31/2025, 2:51 PMoutput: list[ImageContent | TextContent] because its an overkill signature for most tools... but it's the only signature that works for all tools.calm-artist-7206
10/31/2025, 9:12 PMcalm-artist-7206
10/31/2025, 9:13 PM