koder 0.4.6__tar.gz → 0.4.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {koder-0.4.6 → koder-0.4.8}/.claude/settings.local.json +6 -1
- koder-0.4.8/.uv-cache/.gitignore +1 -0
- koder-0.4.8/.uv-cache/CACHEDIR.TAG +1 -0
- koder-0.4.8/.uv-cache/interpreter-v4/aarch64/72afda6228b75bee.msgpack +1 -0
- koder-0.4.8/.uv-cache/sdists-v7/.git +0 -0
- koder-0.4.8/.uv-cache/sdists-v7/.gitignore +0 -0
- {koder-0.4.6 → koder-0.4.8}/PKG-INFO +18 -17
- {koder-0.4.6 → koder-0.4.8}/README.md +1 -1
- koder-0.4.8/koder_agent/agentic/agent.py +409 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/config/models.py +1 -1
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/scheduler.py +41 -20
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/streaming_display.py +93 -31
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/file.py +173 -21
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/task.py +5 -1
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/client.py +92 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/model_info.py +30 -0
- {koder-0.4.6 → koder-0.4.8}/pyproject.toml +17 -16
- koder-0.4.8/tests/test_capture_usage.py +217 -0
- koder-0.4.8/tests/test_file_tools.py +1071 -0
- koder-0.4.8/tests/test_llm_completion_responses.py +65 -0
- koder-0.4.8/tests/test_model_info.py +144 -0
- koder-0.4.8/tests/test_streaming_display.py +381 -0
- koder-0.4.8/tests/test_usage_tracker.py +233 -0
- {koder-0.4.6 → koder-0.4.8}/uv.lock +394 -1098
- koder-0.4.6/koder_agent/agentic/agent.py +0 -147
- koder-0.4.6/tests/test_file_tools.py +0 -496
- {koder-0.4.6 → koder-0.4.8}/.github/dependabot.yml +0 -0
- {koder-0.4.6 → koder-0.4.8}/.gitignore +0 -0
- {koder-0.4.6 → koder-0.4.8}/AGENTS.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/CLAUDE.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/CONTRIBUTING.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/GEMINI.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/LICENSE +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/agentic/skill_guardrail.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/cli.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/config/manager.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/commands.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/keyboard_listener.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/security.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/session.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/status_line.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/core/usage_tracker.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/search.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/skill.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/skill_context.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/tools/web.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/fixtures/skills/large-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/fixtures/skills/large-skill/reference.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/fixtures/skills/medium-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/fixtures/skills/small-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/fixtures/skills/template-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/test_model_resolution.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/test_shell_background.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/test_skill_loader.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/test_skill_restrictions.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/test_skill_token_efficiency.py +0 -0
- {koder-0.4.6 → koder-0.4.8}/tests/test_web.py +0 -0
|
@@ -11,7 +11,12 @@
|
|
|
11
11
|
"Bash(uv run ruff check:*)",
|
|
12
12
|
"mcp__firecrawl__firecrawl_scrape",
|
|
13
13
|
"Bash(uv run:*)",
|
|
14
|
-
"Bash(uv run pip:*)"
|
|
14
|
+
"Bash(uv run pip:*)",
|
|
15
|
+
"Bash(KODER_MODEL=\"github_copilot/gpt-5.1-codex\" uv run koder:*)",
|
|
16
|
+
"Bash(python3:*)",
|
|
17
|
+
"Bash(timeout 90 bash -c \"KODER_MODEL=''github_copilot/gpt-5.1-codex'' uv run koder ''respond with just hello''\")",
|
|
18
|
+
"Bash(git add:*)",
|
|
19
|
+
"Bash(git commit:*)"
|
|
15
20
|
],
|
|
16
21
|
"deny": [],
|
|
17
22
|
"ask": []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Signature: 8a477f597d28d172789f06886806bc55
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
���g����*������macos�aarch64��implementation_name�cpython�implementation_version�3.13.1�os_name�posix�platform_machine�arm64�platform_python_implementation�CPython�platform_release�25.1.0�platform_system�Darwin�platform_version�eDarwin Kernel Version 25.1.0: Mon Oct 20 19:34:03 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8112�python_full_version�3.13.1�python_version�3.13�sys_platform�darwin��@/Users/fei/coding-agent/koder/.venv/lib/python3.13/site-packages�@/Users/fei/coding-agent/koder/.venv/lib/python3.13/site-packages�'/Users/fei/coding-agent/koder/.venv/bin�#/Users/fei/coding-agent/koder/.venv�;/Users/fei/coding-agent/koder/.venv/include/site/python3.13��lib/python3.13/site-packages�lib/python3.13/site-packages�bin��include/site/python3.13��#/Users/fei/coding-agent/koder/.venv�C/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none�C/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none�R/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/bin/python3.13�//Users/fei/coding-agent/koder/.venv/bin/python3��2/Users/fei/coding-agent/koder/.uv-cache/.tmpX75eW6�U/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python313.zip�R/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13�^/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13/lib-dynload�@/Users/fei/coding-agent/koder/.venv/lib/python3.13/site-packages�/Users/fei/coding-agent/koder�R/Users/fei/.local/share/uv/python/cpython-3.13.1-macos-aarch64-none/lib/python3.13â64�
|
|
File without changes
|
|
File without changes
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koder
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
4
4
|
Summary: An intuitive AI coding assistant and interactive CLI tool that boosts developer productivity with intelligent automation and context-aware support.
|
|
5
5
|
Project-URL: Homepage, https://github.com/feiskyer/koder
|
|
6
6
|
Project-URL: Repository, https://github.com/feiskyer/koder
|
|
7
7
|
Author: Pengfei Ni
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Keywords: agent,agentic,ai,copilot,litellm,openai,vibe coding
|
|
10
|
-
Requires-Python: >=3.
|
|
11
|
-
Requires-Dist: aiosqlite>=0.
|
|
12
|
-
Requires-Dist: apscheduler>=3.11.
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: aiosqlite>=0.22.1
|
|
12
|
+
Requires-Dist: apscheduler>=3.11.2
|
|
13
13
|
Requires-Dist: backoff>=2.2.1
|
|
14
|
-
Requires-Dist: beautifulsoup4>=4.14.
|
|
14
|
+
Requires-Dist: beautifulsoup4>=4.14.3
|
|
15
15
|
Requires-Dist: cryptography>=46.0.3
|
|
16
|
-
Requires-Dist: ddgs>=
|
|
17
|
-
Requires-Dist: fastapi-sso>=0.
|
|
18
|
-
Requires-Dist: fastapi>=0.
|
|
19
|
-
Requires-Dist: google-cloud-aiplatform>=1.
|
|
16
|
+
Requires-Dist: ddgs>=9.10.0
|
|
17
|
+
Requires-Dist: fastapi-sso>=0.19.0
|
|
18
|
+
Requires-Dist: fastapi>=0.127.0
|
|
19
|
+
Requires-Dist: google-cloud-aiplatform>=1.132.0
|
|
20
20
|
Requires-Dist: httpx[socks]>=0.28.1
|
|
21
|
-
Requires-Dist: litellm>=1.80.
|
|
22
|
-
Requires-Dist: openai-agents[litellm]>=0.6.
|
|
23
|
-
Requires-Dist: openai>=2.
|
|
24
|
-
Requires-Dist: orjson>=3.11.
|
|
21
|
+
Requires-Dist: litellm>=1.80.11
|
|
22
|
+
Requires-Dist: openai-agents[litellm]>=0.6.4
|
|
23
|
+
Requires-Dist: openai>=2.14.0
|
|
24
|
+
Requires-Dist: orjson>=3.11.5
|
|
25
25
|
Requires-Dist: prompt-toolkit>=3.0.52
|
|
26
|
-
Requires-Dist: pydantic>=2.12.
|
|
26
|
+
Requires-Dist: pydantic>=2.12.5
|
|
27
27
|
Requires-Dist: pyjwt>=2.10.1
|
|
28
28
|
Requires-Dist: pynacl>=1.6.1
|
|
29
|
-
Requires-Dist: python-multipart>=0.0.
|
|
30
|
-
Requires-Dist: pyyaml>=6.0
|
|
29
|
+
Requires-Dist: python-multipart>=0.0.21
|
|
30
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
31
31
|
Requires-Dist: requests>=2.32.5
|
|
32
32
|
Requires-Dist: rich>=14.2.0
|
|
33
33
|
Requires-Dist: tiktoken>=0.12.0
|
|
34
34
|
Requires-Dist: websockets>=15.0.1
|
|
35
|
+
Requires-Dist: whatthepatch>=1.0.7
|
|
35
36
|
Description-Content-Type: text/markdown
|
|
36
37
|
|
|
37
38
|
# Koder
|
|
@@ -133,7 +134,7 @@ model:
|
|
|
133
134
|
base_url: null # Custom API endpoint (optional)
|
|
134
135
|
|
|
135
136
|
# Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
|
|
136
|
-
reasoning_effort:
|
|
137
|
+
reasoning_effort: null # none, minimal, low, medium, high, or null (default: null)
|
|
137
138
|
|
|
138
139
|
# CLI defaults
|
|
139
140
|
cli:
|
|
@@ -97,7 +97,7 @@ model:
|
|
|
97
97
|
base_url: null # Custom API endpoint (optional)
|
|
98
98
|
|
|
99
99
|
# Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
|
|
100
|
-
reasoning_effort:
|
|
100
|
+
reasoning_effort: null # none, minimal, low, medium, high, or null (default: null)
|
|
101
101
|
|
|
102
102
|
# CLI defaults
|
|
103
103
|
cli:
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"""Agent definitions and hooks for Koder."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import uuid
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import backoff
|
|
9
|
+
import litellm
|
|
10
|
+
from agents import Agent, ModelSettings
|
|
11
|
+
from agents.extensions.models.litellm_model import LitellmModel
|
|
12
|
+
from agents.items import ItemHelpers, ModelResponse, TResponseStreamEvent
|
|
13
|
+
from agents.models.openai_responses import Converter as ResponsesConverter
|
|
14
|
+
from agents.tracing import generation_span
|
|
15
|
+
from agents.usage import Usage
|
|
16
|
+
from agents.util._json import _to_dump_compatible
|
|
17
|
+
from openai import omit
|
|
18
|
+
from openai._models import construct_type
|
|
19
|
+
from openai.types.shared import Reasoning
|
|
20
|
+
from rich.console import Console
|
|
21
|
+
|
|
22
|
+
from ..config import get_config
|
|
23
|
+
from ..mcp import load_mcp_servers
|
|
24
|
+
from ..tools.skill import SkillLoader
|
|
25
|
+
from ..utils.client import get_litellm_model_kwargs, get_model_name, is_native_openai_provider
|
|
26
|
+
from ..utils.model_info import get_maximum_output_tokens, should_use_reasoning_param
|
|
27
|
+
from ..utils.prompts import KODER_SYSTEM_PROMPT
|
|
28
|
+
|
|
29
|
+
console = Console()
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class RetryingLitellmModel(LitellmModel):
|
|
34
|
+
"""LitellmModel with backoff retry logic."""
|
|
35
|
+
|
|
36
|
+
_EXC = getattr(litellm, "exceptions", litellm)
|
|
37
|
+
_EXC_TUPLE = (
|
|
38
|
+
getattr(_EXC, "ServiceUnavailableError", Exception),
|
|
39
|
+
getattr(_EXC, "RateLimitError", Exception),
|
|
40
|
+
getattr(_EXC, "APIConnectionError", Exception),
|
|
41
|
+
getattr(_EXC, "Timeout", Exception),
|
|
42
|
+
getattr(_EXC, "InternalServerError", Exception),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def _should_use_responses_api(self) -> bool:
|
|
46
|
+
"""
|
|
47
|
+
GitHub Copilot Codex models are not accessible via /chat/completions.
|
|
48
|
+
Route them through LiteLLM's Responses API instead.
|
|
49
|
+
"""
|
|
50
|
+
model_lower = str(self.model).lower()
|
|
51
|
+
return "github_copilot/" in model_lower and "codex" in model_lower
|
|
52
|
+
|
|
53
|
+
async def _fetch_responses_api(
|
|
54
|
+
self,
|
|
55
|
+
system_instructions: str | None,
|
|
56
|
+
input: str | list,
|
|
57
|
+
model_settings: ModelSettings,
|
|
58
|
+
tools: list,
|
|
59
|
+
output_schema,
|
|
60
|
+
handoffs: list,
|
|
61
|
+
*,
|
|
62
|
+
previous_response_id: str | None,
|
|
63
|
+
stream: bool,
|
|
64
|
+
prompt: Any | None,
|
|
65
|
+
):
|
|
66
|
+
if not hasattr(litellm, "aresponses"):
|
|
67
|
+
raise RuntimeError(
|
|
68
|
+
"GitHub Copilot Codex models require LiteLLM Responses API support. "
|
|
69
|
+
"Please upgrade litellm to a version that provides `aresponses`."
|
|
70
|
+
)
|
|
71
|
+
list_input = ItemHelpers.input_to_new_input_list(input)
|
|
72
|
+
list_input = _to_dump_compatible(list_input)
|
|
73
|
+
|
|
74
|
+
if model_settings.parallel_tool_calls and tools:
|
|
75
|
+
parallel_tool_calls: bool | None = True
|
|
76
|
+
elif model_settings.parallel_tool_calls is False:
|
|
77
|
+
parallel_tool_calls = False
|
|
78
|
+
else:
|
|
79
|
+
parallel_tool_calls = None
|
|
80
|
+
|
|
81
|
+
tool_choice = ResponsesConverter.convert_tool_choice(model_settings.tool_choice)
|
|
82
|
+
if tool_choice is omit:
|
|
83
|
+
tool_choice = None
|
|
84
|
+
|
|
85
|
+
converted_tools = ResponsesConverter.convert_tools(tools, handoffs)
|
|
86
|
+
tools_payload = _to_dump_compatible(converted_tools.tools)
|
|
87
|
+
if not tools_payload:
|
|
88
|
+
tools_payload = None
|
|
89
|
+
|
|
90
|
+
text_param = ResponsesConverter.get_response_format(output_schema)
|
|
91
|
+
if text_param is omit:
|
|
92
|
+
text_param = None
|
|
93
|
+
|
|
94
|
+
include_set = set(converted_tools.includes)
|
|
95
|
+
response_include = getattr(model_settings, "response_include", None)
|
|
96
|
+
if response_include is not None:
|
|
97
|
+
include_set.update(response_include)
|
|
98
|
+
top_logprobs = getattr(model_settings, "top_logprobs", None)
|
|
99
|
+
if top_logprobs is not None:
|
|
100
|
+
include_set.add("message.output_text.logprobs")
|
|
101
|
+
include = list(include_set) if include_set else None
|
|
102
|
+
|
|
103
|
+
extra_args: dict[str, Any] = dict(model_settings.extra_args or {})
|
|
104
|
+
if top_logprobs is not None:
|
|
105
|
+
extra_args["top_logprobs"] = top_logprobs
|
|
106
|
+
verbosity = getattr(model_settings, "verbosity", None)
|
|
107
|
+
if verbosity is not None:
|
|
108
|
+
if text_param is not None and isinstance(text_param, dict):
|
|
109
|
+
text_param["verbosity"] = verbosity
|
|
110
|
+
else:
|
|
111
|
+
text_param = {"verbosity": verbosity}
|
|
112
|
+
|
|
113
|
+
aresponses_kwargs: dict[str, Any] = {
|
|
114
|
+
"model": self.model,
|
|
115
|
+
"input": list_input,
|
|
116
|
+
"include": include,
|
|
117
|
+
"instructions": system_instructions,
|
|
118
|
+
"tools": tools_payload,
|
|
119
|
+
"tool_choice": tool_choice,
|
|
120
|
+
"parallel_tool_calls": parallel_tool_calls,
|
|
121
|
+
"temperature": model_settings.temperature,
|
|
122
|
+
"top_p": model_settings.top_p,
|
|
123
|
+
"truncation": getattr(model_settings, "truncation", None),
|
|
124
|
+
"max_output_tokens": model_settings.max_tokens,
|
|
125
|
+
"reasoning": getattr(model_settings, "reasoning", None),
|
|
126
|
+
"metadata": model_settings.metadata,
|
|
127
|
+
"previous_response_id": previous_response_id,
|
|
128
|
+
"prompt": prompt,
|
|
129
|
+
"stream": stream,
|
|
130
|
+
"extra_headers": self._merge_headers(model_settings),
|
|
131
|
+
"extra_query": model_settings.extra_query,
|
|
132
|
+
"extra_body": model_settings.extra_body,
|
|
133
|
+
**extra_args,
|
|
134
|
+
}
|
|
135
|
+
if self.api_key:
|
|
136
|
+
aresponses_kwargs["api_key"] = self.api_key
|
|
137
|
+
if self.base_url:
|
|
138
|
+
aresponses_kwargs["base_url"] = self.base_url
|
|
139
|
+
|
|
140
|
+
return await litellm.aresponses(**aresponses_kwargs)
|
|
141
|
+
|
|
142
|
+
@backoff.on_exception(
|
|
143
|
+
backoff.expo,
|
|
144
|
+
_EXC_TUPLE,
|
|
145
|
+
max_tries=3,
|
|
146
|
+
jitter=backoff.full_jitter,
|
|
147
|
+
)
|
|
148
|
+
async def get_response(
|
|
149
|
+
self,
|
|
150
|
+
system_instructions: str | None,
|
|
151
|
+
input: str | list,
|
|
152
|
+
model_settings: ModelSettings,
|
|
153
|
+
tools: list,
|
|
154
|
+
output_schema,
|
|
155
|
+
handoffs: list,
|
|
156
|
+
tracing,
|
|
157
|
+
previous_response_id: str | None = None,
|
|
158
|
+
conversation_id: str | None = None, # unused for LiteLLM responses
|
|
159
|
+
prompt: Any | None = None,
|
|
160
|
+
) -> ModelResponse:
|
|
161
|
+
if not self._should_use_responses_api():
|
|
162
|
+
return await super().get_response(
|
|
163
|
+
system_instructions,
|
|
164
|
+
input,
|
|
165
|
+
model_settings,
|
|
166
|
+
tools,
|
|
167
|
+
output_schema,
|
|
168
|
+
handoffs,
|
|
169
|
+
tracing,
|
|
170
|
+
previous_response_id=previous_response_id,
|
|
171
|
+
conversation_id=conversation_id,
|
|
172
|
+
prompt=prompt,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
with generation_span(
|
|
176
|
+
model=str(self.model),
|
|
177
|
+
model_config=model_settings.to_json_dict()
|
|
178
|
+
| {"base_url": str(self.base_url or ""), "model_impl": "litellm-responses"},
|
|
179
|
+
disabled=tracing.is_disabled(),
|
|
180
|
+
) as span_generation:
|
|
181
|
+
response = await self._fetch_responses_api(
|
|
182
|
+
system_instructions,
|
|
183
|
+
input,
|
|
184
|
+
model_settings,
|
|
185
|
+
tools,
|
|
186
|
+
output_schema,
|
|
187
|
+
handoffs,
|
|
188
|
+
previous_response_id=previous_response_id,
|
|
189
|
+
stream=False,
|
|
190
|
+
prompt=prompt,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
response_usage = getattr(response, "usage", None)
|
|
194
|
+
if response_usage:
|
|
195
|
+
usage_kwargs: dict[str, Any] = {
|
|
196
|
+
"requests": 1,
|
|
197
|
+
"input_tokens": getattr(response_usage, "input_tokens", 0) or 0,
|
|
198
|
+
"output_tokens": getattr(response_usage, "output_tokens", 0) or 0,
|
|
199
|
+
"total_tokens": getattr(response_usage, "total_tokens", 0) or 0,
|
|
200
|
+
}
|
|
201
|
+
usage = Usage(**usage_kwargs)
|
|
202
|
+
span_generation.span_data.usage = {
|
|
203
|
+
"input_tokens": usage.input_tokens,
|
|
204
|
+
"output_tokens": usage.output_tokens,
|
|
205
|
+
}
|
|
206
|
+
else:
|
|
207
|
+
usage = Usage()
|
|
208
|
+
|
|
209
|
+
if tracing.include_data():
|
|
210
|
+
try:
|
|
211
|
+
span_generation.span_data.output = (
|
|
212
|
+
[response.model_dump()] if hasattr(response, "model_dump") else [response]
|
|
213
|
+
)
|
|
214
|
+
except Exception:
|
|
215
|
+
pass
|
|
216
|
+
|
|
217
|
+
return ModelResponse(
|
|
218
|
+
output=getattr(response, "output", []) or [],
|
|
219
|
+
usage=usage,
|
|
220
|
+
response_id=getattr(response, "id", None),
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
@backoff.on_exception(
|
|
224
|
+
backoff.expo,
|
|
225
|
+
_EXC_TUPLE,
|
|
226
|
+
max_tries=5,
|
|
227
|
+
jitter=backoff.full_jitter,
|
|
228
|
+
)
|
|
229
|
+
async def stream_response(
|
|
230
|
+
self,
|
|
231
|
+
system_instructions: str | None,
|
|
232
|
+
input: str | list,
|
|
233
|
+
model_settings: ModelSettings,
|
|
234
|
+
tools: list,
|
|
235
|
+
output_schema,
|
|
236
|
+
handoffs: list,
|
|
237
|
+
tracing,
|
|
238
|
+
previous_response_id: str | None = None,
|
|
239
|
+
conversation_id: str | None = None, # unused for LiteLLM responses
|
|
240
|
+
prompt: Any | None = None,
|
|
241
|
+
):
|
|
242
|
+
if not self._should_use_responses_api():
|
|
243
|
+
async for chunk in super().stream_response(
|
|
244
|
+
system_instructions,
|
|
245
|
+
input,
|
|
246
|
+
model_settings,
|
|
247
|
+
tools,
|
|
248
|
+
output_schema,
|
|
249
|
+
handoffs,
|
|
250
|
+
tracing,
|
|
251
|
+
previous_response_id=previous_response_id,
|
|
252
|
+
conversation_id=conversation_id,
|
|
253
|
+
prompt=prompt,
|
|
254
|
+
):
|
|
255
|
+
yield chunk
|
|
256
|
+
return
|
|
257
|
+
|
|
258
|
+
with generation_span(
|
|
259
|
+
model=str(self.model),
|
|
260
|
+
model_config=model_settings.to_json_dict()
|
|
261
|
+
| {"base_url": str(self.base_url or ""), "model_impl": "litellm-responses"},
|
|
262
|
+
disabled=tracing.is_disabled(),
|
|
263
|
+
) as span_generation:
|
|
264
|
+
stream = await self._fetch_responses_api(
|
|
265
|
+
system_instructions,
|
|
266
|
+
input,
|
|
267
|
+
model_settings,
|
|
268
|
+
tools,
|
|
269
|
+
output_schema,
|
|
270
|
+
handoffs,
|
|
271
|
+
previous_response_id=previous_response_id,
|
|
272
|
+
stream=True,
|
|
273
|
+
prompt=prompt,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
final_response = None
|
|
277
|
+
async for chunk in stream:
|
|
278
|
+
if hasattr(chunk, "model_dump"):
|
|
279
|
+
try:
|
|
280
|
+
data = chunk.model_dump()
|
|
281
|
+
except Exception:
|
|
282
|
+
data = chunk
|
|
283
|
+
else:
|
|
284
|
+
data = chunk
|
|
285
|
+
|
|
286
|
+
if isinstance(data, dict):
|
|
287
|
+
event_type = data.get("type")
|
|
288
|
+
if hasattr(event_type, "value"):
|
|
289
|
+
data["type"] = event_type.value
|
|
290
|
+
elif not isinstance(event_type, str):
|
|
291
|
+
data["type"] = str(event_type)
|
|
292
|
+
event = construct_type(value=data, type_=TResponseStreamEvent)
|
|
293
|
+
else:
|
|
294
|
+
event = chunk
|
|
295
|
+
|
|
296
|
+
if getattr(event, "type", None) == "response.completed":
|
|
297
|
+
final_response = getattr(event, "response", None)
|
|
298
|
+
yield event
|
|
299
|
+
|
|
300
|
+
if final_response is not None and getattr(final_response, "usage", None):
|
|
301
|
+
usage_obj = final_response.usage
|
|
302
|
+
span_generation.span_data.usage = {
|
|
303
|
+
"input_tokens": getattr(usage_obj, "input_tokens", 0) or 0,
|
|
304
|
+
"output_tokens": getattr(usage_obj, "output_tokens", 0) or 0,
|
|
305
|
+
}
|
|
306
|
+
if tracing.include_data() and final_response is not None:
|
|
307
|
+
try:
|
|
308
|
+
span_generation.span_data.output = (
|
|
309
|
+
[final_response.model_dump()]
|
|
310
|
+
if hasattr(final_response, "model_dump")
|
|
311
|
+
else [final_response]
|
|
312
|
+
)
|
|
313
|
+
except Exception:
|
|
314
|
+
pass
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _get_skills_metadata(config) -> str:
|
|
318
|
+
"""Load and return skills metadata from configured directories.
|
|
319
|
+
|
|
320
|
+
Priority: project skills directory > user skills directory.
|
|
321
|
+
Skills with the same name in project dir override user dir.
|
|
322
|
+
"""
|
|
323
|
+
if not config.skills.enabled:
|
|
324
|
+
return "Skills are disabled."
|
|
325
|
+
|
|
326
|
+
all_skills = {}
|
|
327
|
+
|
|
328
|
+
# Load user skills first (lower priority)
|
|
329
|
+
user_dir = Path(config.skills.user_skills_dir).expanduser()
|
|
330
|
+
if user_dir.exists():
|
|
331
|
+
user_loader = SkillLoader(user_dir)
|
|
332
|
+
for skill in user_loader.discover_skills():
|
|
333
|
+
all_skills[skill.name] = skill
|
|
334
|
+
|
|
335
|
+
# Load project skills (higher priority - overrides user skills)
|
|
336
|
+
project_dir = Path(config.skills.project_skills_dir)
|
|
337
|
+
if project_dir.exists():
|
|
338
|
+
project_loader = SkillLoader(project_dir)
|
|
339
|
+
for skill in project_loader.discover_skills():
|
|
340
|
+
all_skills[skill.name] = skill
|
|
341
|
+
|
|
342
|
+
if not all_skills:
|
|
343
|
+
return "No skills are currently available."
|
|
344
|
+
|
|
345
|
+
lines = ["Available skills:", ""]
|
|
346
|
+
for skill in sorted(all_skills.values(), key=lambda s: s.name.lower()):
|
|
347
|
+
description = skill.description.strip()
|
|
348
|
+
lines.append(f"- {skill.name}: {description}")
|
|
349
|
+
|
|
350
|
+
return "\n".join(lines)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
async def create_dev_agent(tools) -> Agent:
|
|
354
|
+
"""Create the main development agent with MCP servers."""
|
|
355
|
+
config = get_config()
|
|
356
|
+
mcp_servers = await load_mcp_servers()
|
|
357
|
+
|
|
358
|
+
# Determine the model to use: native OpenAI string or LitellmModel instance
|
|
359
|
+
if is_native_openai_provider():
|
|
360
|
+
# Use string model name for native OpenAI providers (handled by default client)
|
|
361
|
+
model = get_model_name()
|
|
362
|
+
else:
|
|
363
|
+
# Use LitellmModel with explicit base_url and api_key
|
|
364
|
+
litellm_kwargs = get_litellm_model_kwargs()
|
|
365
|
+
model = RetryingLitellmModel(
|
|
366
|
+
model=litellm_kwargs["model"],
|
|
367
|
+
base_url=litellm_kwargs["base_url"],
|
|
368
|
+
api_key=litellm_kwargs["api_key"],
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
# Build model_settings with reasoning if configured
|
|
372
|
+
model_name_str = get_model_name() # Always get string name for max_tokens lookup
|
|
373
|
+
model_settings = ModelSettings(
|
|
374
|
+
metadata={"source": "koder"},
|
|
375
|
+
max_tokens=get_maximum_output_tokens(model_name_str),
|
|
376
|
+
)
|
|
377
|
+
# Only set reasoning parameter for native OpenAI providers
|
|
378
|
+
# LiteLLM-based providers (GitHub Copilot, Anthropic, etc.) don't support the Reasoning object
|
|
379
|
+
if config.model.reasoning_effort is not None and should_use_reasoning_param():
|
|
380
|
+
effort = None if config.model.reasoning_effort == "none" else config.model.reasoning_effort
|
|
381
|
+
model_settings.reasoning = Reasoning(effort=effort, summary="detailed")
|
|
382
|
+
|
|
383
|
+
# Build system prompt with skills metadata (Progressive Disclosure Level 1)
|
|
384
|
+
skills_metadata = _get_skills_metadata(config)
|
|
385
|
+
system_prompt = KODER_SYSTEM_PROMPT.replace("{SKILLS_METADATA}", skills_metadata)
|
|
386
|
+
|
|
387
|
+
dev_agent = Agent(
|
|
388
|
+
name="Koder",
|
|
389
|
+
model=model,
|
|
390
|
+
instructions=system_prompt,
|
|
391
|
+
tools=tools,
|
|
392
|
+
mcp_servers=mcp_servers,
|
|
393
|
+
model_settings=model_settings,
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
if "github_copilot" in model_name_str:
|
|
397
|
+
dev_agent.model_settings.extra_headers = {
|
|
398
|
+
"copilot-integration-id": "vscode-chat",
|
|
399
|
+
"editor-version": "vscode/1.98.1",
|
|
400
|
+
"editor-plugin-version": "copilot-chat/0.26.7",
|
|
401
|
+
"user-agent": "GitHubCopilotChat/0.26.7",
|
|
402
|
+
"openai-intent": "conversation-panel",
|
|
403
|
+
"x-github-api-version": "2025-04-01",
|
|
404
|
+
"x-request-id": str(uuid.uuid4()),
|
|
405
|
+
"x-vscode-user-agent-library-version": "electron-fetch",
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
# planner.handoffs.append(dev_agent)
|
|
409
|
+
return dev_agent
|
|
@@ -39,7 +39,7 @@ class ModelConfig(BaseModel):
|
|
|
39
39
|
|
|
40
40
|
# NEW: Reasoning effort setting
|
|
41
41
|
reasoning_effort: Optional[Literal["none", "minimal", "low", "medium", "high"]] = Field(
|
|
42
|
-
default=
|
|
42
|
+
default=None,
|
|
43
43
|
description=(
|
|
44
44
|
"Reasoning effort for reasoning models (none, minimal, low, medium, high, or null to"
|
|
45
45
|
" not set)"
|
|
@@ -131,7 +131,7 @@ class AgentScheduler:
|
|
|
131
131
|
max_turns=50,
|
|
132
132
|
)
|
|
133
133
|
# Capture token usage from result
|
|
134
|
-
self._capture_usage(result)
|
|
134
|
+
await self._capture_usage(result)
|
|
135
135
|
|
|
136
136
|
# Filter output for security
|
|
137
137
|
response = self._filter_output(result.final_output)
|
|
@@ -358,7 +358,7 @@ class AgentScheduler:
|
|
|
358
358
|
console.print()
|
|
359
359
|
|
|
360
360
|
# Capture any usage data we can
|
|
361
|
-
self._capture_usage(result)
|
|
361
|
+
await self._capture_usage(result)
|
|
362
362
|
|
|
363
363
|
# Return partial text for session history
|
|
364
364
|
return partial_text or "Operation cancelled. You can provide additional instructions."
|
|
@@ -410,7 +410,7 @@ class AgentScheduler:
|
|
|
410
410
|
print() # Add spacing after
|
|
411
411
|
|
|
412
412
|
# Capture token usage from streaming result
|
|
413
|
-
self._capture_usage(result)
|
|
413
|
+
await self._capture_usage(result)
|
|
414
414
|
|
|
415
415
|
# Get final text response for context saving
|
|
416
416
|
final_response = display_manager.get_final_text()
|
|
@@ -461,28 +461,49 @@ class AgentScheduler:
|
|
|
461
461
|
)
|
|
462
462
|
return text
|
|
463
463
|
|
|
464
|
-
def _capture_usage(self, result) -> None:
|
|
465
|
-
"""Capture token usage from a Runner result.
|
|
464
|
+
async def _capture_usage(self, result) -> None:
|
|
465
|
+
"""Capture token usage from a Runner result.
|
|
466
|
+
|
|
467
|
+
If the API doesn't return usage data, falls back to tiktoken estimation
|
|
468
|
+
using the session's existing _estimate_tokens method.
|
|
469
|
+
"""
|
|
466
470
|
try:
|
|
471
|
+
input_tokens = 0
|
|
472
|
+
output_tokens = 0
|
|
473
|
+
context_tokens = None
|
|
474
|
+
|
|
475
|
+
# Try to get usage from the API response
|
|
467
476
|
if hasattr(result, "context_wrapper") and hasattr(result.context_wrapper, "usage"):
|
|
468
477
|
usage = result.context_wrapper.usage
|
|
469
478
|
input_tokens = getattr(usage, "input_tokens", 0) or 0
|
|
470
479
|
output_tokens = getattr(usage, "output_tokens", 0) or 0
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
480
|
+
|
|
481
|
+
if hasattr(usage, "request_usage_entries") and usage.request_usage_entries:
|
|
482
|
+
last_req = usage.request_usage_entries[-1]
|
|
483
|
+
context_tokens = last_req.total_tokens
|
|
484
|
+
|
|
485
|
+
# Fallback: estimate tokens using session's tiktoken encoder
|
|
486
|
+
if input_tokens <= 0 and output_tokens <= 0:
|
|
487
|
+
# Estimate output tokens from final_output
|
|
488
|
+
final_output = getattr(result, "final_output", None)
|
|
489
|
+
if final_output and hasattr(self.session, "encoder"):
|
|
490
|
+
output_text = str(final_output)
|
|
491
|
+
output_tokens = len(self.session.encoder.encode(output_text))
|
|
492
|
+
|
|
493
|
+
# Estimate input/context tokens from session history
|
|
494
|
+
try:
|
|
495
|
+
session_items = await self.session.get_items()
|
|
496
|
+
if session_items:
|
|
497
|
+
input_tokens = self.session._estimate_tokens(session_items)
|
|
498
|
+
context_tokens = input_tokens + output_tokens
|
|
499
|
+
except Exception:
|
|
500
|
+
pass
|
|
501
|
+
|
|
502
|
+
# Record usage if we have any tokens
|
|
503
|
+
if input_tokens > 0 or output_tokens > 0:
|
|
504
|
+
self.usage_tracker.record_usage(
|
|
505
|
+
input_tokens, output_tokens, context_tokens=context_tokens
|
|
506
|
+
)
|
|
486
507
|
except Exception:
|
|
487
508
|
# Silently ignore usage capture errors
|
|
488
509
|
pass
|