-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(soul): degrade unsupported tool media instead of aborting mid-task #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rainbowgore
wants to merge
1
commit into
MoonshotAI:main
Choose a base branch
from
rainbowgore:fix/2588-capability-error-after-image-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| """Tests for capability handling of media in tool results during _grow_context (#2588).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from kosong import StepResult | ||
| from kosong.message import Message | ||
| from kosong.tooling import ToolOk | ||
| from kosong.tooling.empty import EmptyToolset | ||
|
|
||
| from kimi_cli.llm import LLM, ModelCapability | ||
| from kimi_cli.soul.agent import Agent, Runtime | ||
| from kimi_cli.soul.context import Context | ||
| from kimi_cli.soul.kimisoul import KimiSoul | ||
| from kimi_cli.wire.types import ImageURLPart, TextPart, ToolResult | ||
|
|
||
|
|
||
| def _make_soul(runtime: Runtime, tmp_path: Path) -> KimiSoul: | ||
| agent = Agent( | ||
| name="Grow Context Media Test Agent", | ||
| system_prompt="Test prompt.", | ||
| toolset=EmptyToolset(), | ||
| runtime=runtime, | ||
| ) | ||
| return KimiSoul(agent, context=Context(file_backend=tmp_path / "history.jsonl")) | ||
|
|
||
|
|
||
| def _runtime_with_llm(runtime: Runtime, llm: LLM) -> Runtime: | ||
| return Runtime( | ||
| config=runtime.config, | ||
| llm=llm, | ||
| session=runtime.session, | ||
| builtin_args=runtime.builtin_args, | ||
| denwa_renji=runtime.denwa_renji, | ||
| approval=runtime.approval, | ||
| labor_market=runtime.labor_market, | ||
| environment=runtime.environment, | ||
| notifications=runtime.notifications, | ||
| background_tasks=runtime.background_tasks, | ||
| skills=runtime.skills, | ||
| oauth=runtime.oauth, | ||
| additional_dirs=runtime.additional_dirs, | ||
| skills_dirs=runtime.skills_dirs, | ||
| ) | ||
|
|
||
|
|
||
| def _llm_with_capabilities(runtime: Runtime, capabilities: set[ModelCapability]) -> LLM: | ||
| assert runtime.llm is not None | ||
| return LLM( | ||
| chat_provider=runtime.llm.chat_provider, | ||
| max_context_size=runtime.llm.max_context_size, | ||
| capabilities=capabilities, | ||
| model_config=runtime.llm.model_config, | ||
| provider_config=runtime.llm.provider_config, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_grow_context_omits_image_when_model_lacks_image_in( | ||
| runtime: Runtime, tmp_path: Path | ||
| ) -> None: | ||
| soul = _make_soul(_runtime_with_llm(runtime, _llm_with_capabilities(runtime, set())), tmp_path) | ||
|
|
||
| await soul.context.append_message(Message(role="user", content=[TextPart(text="edit doc")])) | ||
| await soul.context.append_message( | ||
| Message(role="assistant", content=[TextPart(text="edited successfully")]) | ||
| ) | ||
|
|
||
| img = ImageURLPart(image_url=ImageURLPart.ImageURL(url="data:image/png;base64,AAA")) | ||
| tool_results = [ | ||
| ToolResult( | ||
| tool_call_id="call_screenshot", | ||
| return_value=ToolOk(message="screenshot captured", output=img), | ||
| ) | ||
| ] | ||
| step = StepResult( | ||
| id="step1", | ||
| message=Message(role="assistant", content=[TextPart(text="taking screenshot")]), | ||
| usage=None, | ||
| tool_calls=[], | ||
| _tool_result_futures={}, | ||
| ) | ||
|
|
||
| await soul._grow_context(step, tool_results) | ||
|
|
||
| # Prior side effects remain, and the turn continues with a text stand-in. | ||
| assert len(soul.context.history) == 4 | ||
| tool_msg = soul.context.history[-1] | ||
| assert tool_msg.role == "tool" | ||
| assert tool_msg.tool_call_id == "call_screenshot" | ||
| assert not any(isinstance(part, ImageURLPart) for part in tool_msg.content) | ||
| assert any( | ||
| isinstance(part, TextPart) and "Image omitted" in part.text for part in tool_msg.content | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_grow_context_keeps_image_when_model_has_image_in( | ||
| runtime: Runtime, tmp_path: Path | ||
| ) -> None: | ||
| soul = _make_soul( | ||
| _runtime_with_llm(runtime, _llm_with_capabilities(runtime, {"image_in"})), | ||
| tmp_path, | ||
| ) | ||
|
|
||
| img = ImageURLPart(image_url=ImageURLPart.ImageURL(url="data:image/png;base64,AAA")) | ||
| tool_results = [ | ||
| ToolResult( | ||
| tool_call_id="call_screenshot", | ||
| return_value=ToolOk(message="screenshot captured", output=img), | ||
| ) | ||
| ] | ||
| step = StepResult( | ||
| id="step1", | ||
| message=Message(role="assistant", content=[TextPart(text="taking screenshot")]), | ||
| usage=None, | ||
| tool_calls=[], | ||
| _tool_result_futures={}, | ||
| ) | ||
|
|
||
| await soul._grow_context(step, tool_results) | ||
|
|
||
| tool_msg = soul.context.history[-1] | ||
| assert any(isinstance(part, ImageURLPart) for part in tool_msg.content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Chinese documentation uses a translated word for a term the style guide requires to stay in English
The Chinese providers page describes the agent as "代理" (
docs/zh/configuration/providers.md:136), but the documentation term table mandates keeping "Agent" as a proper noun in Chinese, so the wording is inconsistent with the rest of the docs.Impact: Readers of the Chinese docs see a term that differs from every other page, making the concept harder to recognize.
Term-mapping rule in docs/AGENTS.md
docs/AGENTS.mdcontains a term mapping table stating Chinese "Agent" ↔ English "agent", with "Proper noun (zh) = yes", meaning the Chinese text must keep the English wordAgentrather than translating it to 代理. All other Chinese docs follow this (e.g. 子 Agent).Was this helpful? React with 👍 or 👎 to provide feedback.