koder 0.4.6__tar.gz → 0.4.7__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.7}/.claude/settings.local.json +4 -1
- {koder-0.4.6 → koder-0.4.7}/PKG-INFO +13 -13
- {koder-0.4.6 → koder-0.4.7}/README.md +1 -1
- koder-0.4.7/koder_agent/agentic/agent.py +409 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/config/models.py +1 -1
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/task.py +5 -1
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/client.py +92 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/model_info.py +22 -0
- {koder-0.4.6 → koder-0.4.7}/pyproject.toml +12 -12
- koder-0.4.7/tests/test_llm_completion_responses.py +65 -0
- {koder-0.4.6 → koder-0.4.7}/uv.lock +344 -1129
- koder-0.4.6/koder_agent/agentic/agent.py +0 -147
- {koder-0.4.6 → koder-0.4.7}/.github/dependabot.yml +0 -0
- {koder-0.4.6 → koder-0.4.7}/.gitignore +0 -0
- {koder-0.4.6 → koder-0.4.7}/AGENTS.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/CLAUDE.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/CONTRIBUTING.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/GEMINI.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/LICENSE +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/agentic/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/agentic/approval_hooks.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/agentic/hooks.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/agentic/skill_guardrail.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/cli.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/config/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/config/cli_handler.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/config/manager.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/commands.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/interactive.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/keyboard_listener.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/scheduler.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/security.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/session.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/status_line.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/streaming_display.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/core/usage_tracker.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/mcp/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/mcp/cli_handler.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/mcp/server_config.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/mcp/server_factory.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/mcp/server_manager.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/engine.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/file.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/search.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/shell.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/skill.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/skill_context.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/todo.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/tools/web.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/__init__.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/prompts.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/queue.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/sessions.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/koder_agent/utils/terminal_theme.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/scripts/upgrade_dependency.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/fixtures/skills/large-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/fixtures/skills/large-skill/reference.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/fixtures/skills/medium-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/fixtures/skills/small-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/fixtures/skills/template-skill/SKILL.md +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_file_tools.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_model_resolution.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_shell_background.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_skill_loader.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_skill_restrictions.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_skill_token_efficiency.py +0 -0
- {koder-0.4.6 → koder-0.4.7}/tests/test_web.py +0 -0
|
@@ -11,7 +11,10 @@
|
|
|
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''\")"
|
|
15
18
|
],
|
|
16
19
|
"deny": [],
|
|
17
20
|
"ask": []
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koder
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.7
|
|
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.
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
11
|
Requires-Dist: aiosqlite>=0.21.0
|
|
12
12
|
Requires-Dist: apscheduler>=3.11.1
|
|
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>=
|
|
16
|
+
Requires-Dist: ddgs>=9.9.3
|
|
17
17
|
Requires-Dist: fastapi-sso>=0.18.0
|
|
18
|
-
Requires-Dist: fastapi>=0.
|
|
19
|
-
Requires-Dist: google-cloud-aiplatform>=1.
|
|
18
|
+
Requires-Dist: fastapi>=0.124.2
|
|
19
|
+
Requires-Dist: google-cloud-aiplatform>=1.130.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.9
|
|
22
|
+
Requires-Dist: openai-agents[litellm]>=0.6.3
|
|
23
|
+
Requires-Dist: openai>=2.11.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
29
|
Requires-Dist: python-multipart>=0.0.20
|
|
30
|
-
Requires-Dist: pyyaml>=6.0
|
|
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
|
|
@@ -133,7 +133,7 @@ model:
|
|
|
133
133
|
base_url: null # Custom API endpoint (optional)
|
|
134
134
|
|
|
135
135
|
# Reasoning effort for OpenAI reasoning models (o1, o3, gpt-5.1, etc.)
|
|
136
|
-
reasoning_effort:
|
|
136
|
+
reasoning_effort: null # none, minimal, low, medium, high, or null (default: null)
|
|
137
137
|
|
|
138
138
|
# CLI defaults
|
|
139
139
|
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)"
|
|
@@ -50,8 +50,12 @@ async def task_delegate(tasks: Union[List[TaskModel], TaskModel]) -> str:
|
|
|
50
50
|
tools = [tool for tool in tools if tool.name != "task_delegate"]
|
|
51
51
|
|
|
52
52
|
# Build model_settings with reasoning if configured
|
|
53
|
+
# Only set reasoning parameter for native OpenAI providers
|
|
54
|
+
# LiteLLM-based providers (GitHub Copilot, Anthropic, etc.) don't support it
|
|
55
|
+
from ..utils.model_info import should_use_reasoning_param
|
|
56
|
+
|
|
53
57
|
model_settings = ModelSettings()
|
|
54
|
-
if config.model.reasoning_effort is not None:
|
|
58
|
+
if config.model.reasoning_effort is not None and should_use_reasoning_param():
|
|
55
59
|
model_settings.reasoning = Reasoning(effort=config.model.reasoning_effort)
|
|
56
60
|
|
|
57
61
|
# Create agent for the delegated task
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""OpenAI client setup with configuration support."""
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
|
+
import uuid
|
|
4
5
|
from typing import Optional
|
|
5
6
|
|
|
6
7
|
import backoff
|
|
@@ -354,10 +355,101 @@ async def llm_completion(messages: list, model: Optional[str] = None) -> str:
|
|
|
354
355
|
if base_url:
|
|
355
356
|
kwargs["base_url"] = base_url
|
|
356
357
|
|
|
358
|
+
model_lower = str(model).lower()
|
|
359
|
+
is_copilot = "github_copilot/" in model_lower
|
|
360
|
+
extra_headers = None
|
|
361
|
+
if is_copilot:
|
|
362
|
+
extra_headers = {
|
|
363
|
+
"copilot-integration-id": "vscode-chat",
|
|
364
|
+
"editor-version": "vscode/1.98.1",
|
|
365
|
+
"editor-plugin-version": "copilot-chat/0.26.7",
|
|
366
|
+
"user-agent": "GitHubCopilotChat/0.26.7",
|
|
367
|
+
"openai-intent": "conversation-panel",
|
|
368
|
+
"x-github-api-version": "2025-04-01",
|
|
369
|
+
"x-request-id": str(uuid.uuid4()),
|
|
370
|
+
"x-vscode-user-agent-library-version": "electron-fetch",
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if is_copilot and "codex" in model_lower:
|
|
374
|
+
if not hasattr(litellm, "aresponses"):
|
|
375
|
+
raise RuntimeError(
|
|
376
|
+
"GitHub Copilot Codex models require LiteLLM Responses API support. "
|
|
377
|
+
"Please upgrade litellm to a version that provides `aresponses`."
|
|
378
|
+
)
|
|
379
|
+
responses_kwargs = {
|
|
380
|
+
"model": model,
|
|
381
|
+
"input": messages,
|
|
382
|
+
"metadata": {"source": "koder"},
|
|
383
|
+
"stream": False,
|
|
384
|
+
}
|
|
385
|
+
if api_key:
|
|
386
|
+
responses_kwargs["api_key"] = api_key
|
|
387
|
+
if base_url:
|
|
388
|
+
responses_kwargs["base_url"] = base_url
|
|
389
|
+
if extra_headers:
|
|
390
|
+
responses_kwargs["extra_headers"] = extra_headers
|
|
391
|
+
response = await litellm.aresponses(**responses_kwargs)
|
|
392
|
+
return _extract_responses_text(response)
|
|
393
|
+
|
|
394
|
+
if extra_headers:
|
|
395
|
+
kwargs["extra_headers"] = extra_headers
|
|
357
396
|
response = await litellm.acompletion(**kwargs)
|
|
358
397
|
return response.choices[0].message.content
|
|
359
398
|
|
|
360
399
|
|
|
400
|
+
def _extract_responses_text(response: object) -> str:
|
|
401
|
+
"""
|
|
402
|
+
Best-effort extraction of assistant text from a LiteLLM Responses API response.
|
|
403
|
+
Handles dict-like and pydantic-like objects.
|
|
404
|
+
"""
|
|
405
|
+
output_text = getattr(response, "output_text", None)
|
|
406
|
+
if isinstance(output_text, str) and output_text.strip():
|
|
407
|
+
return output_text
|
|
408
|
+
|
|
409
|
+
output = getattr(response, "output", None)
|
|
410
|
+
if output is None and isinstance(response, dict):
|
|
411
|
+
output = response.get("output")
|
|
412
|
+
|
|
413
|
+
if isinstance(output, list):
|
|
414
|
+
parts: list[str] = []
|
|
415
|
+
for item in output:
|
|
416
|
+
item_dict = item
|
|
417
|
+
if hasattr(item, "model_dump"):
|
|
418
|
+
try:
|
|
419
|
+
item_dict = item.model_dump()
|
|
420
|
+
except Exception:
|
|
421
|
+
item_dict = item
|
|
422
|
+
if not isinstance(item_dict, dict):
|
|
423
|
+
continue
|
|
424
|
+
if item_dict.get("type") == "message":
|
|
425
|
+
for content in item_dict.get("content", []) or []:
|
|
426
|
+
if isinstance(content, dict) and content.get("type") in (
|
|
427
|
+
"output_text",
|
|
428
|
+
"text",
|
|
429
|
+
):
|
|
430
|
+
text_val = content.get("text") or content.get("content")
|
|
431
|
+
if text_val:
|
|
432
|
+
parts.append(str(text_val))
|
|
433
|
+
elif item_dict.get("type") in ("output_text", "text"):
|
|
434
|
+
text_val = item_dict.get("text")
|
|
435
|
+
if text_val:
|
|
436
|
+
parts.append(str(text_val))
|
|
437
|
+
if parts:
|
|
438
|
+
return "".join(parts).strip()
|
|
439
|
+
|
|
440
|
+
if isinstance(response, dict):
|
|
441
|
+
try:
|
|
442
|
+
first = response.get("output", [])[0]
|
|
443
|
+
if isinstance(first, dict):
|
|
444
|
+
content = first.get("content", [])
|
|
445
|
+
if content and isinstance(content[0], dict):
|
|
446
|
+
return str(content[0].get("text", "")).strip()
|
|
447
|
+
except Exception:
|
|
448
|
+
pass
|
|
449
|
+
|
|
450
|
+
return ""
|
|
451
|
+
|
|
452
|
+
|
|
361
453
|
def setup_openai_client():
|
|
362
454
|
"""Set up the OpenAI client with priority: ENV > Config > Default.
|
|
363
455
|
|
|
@@ -108,3 +108,25 @@ def get_summarization_threshold(model: str, threshold_ratio: float = 0.8) -> int
|
|
|
108
108
|
"""
|
|
109
109
|
context_size = get_context_window_size(model)
|
|
110
110
|
return int(context_size * threshold_ratio)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def should_use_reasoning_param() -> bool:
|
|
114
|
+
"""
|
|
115
|
+
Check if the current provider/model configuration supports the Reasoning parameter.
|
|
116
|
+
|
|
117
|
+
The Reasoning object from openai.types.shared is only compatible with:
|
|
118
|
+
- Native OpenAI API calls (not through LiteLLM)
|
|
119
|
+
- Models that actually support reasoning (o1, o3, o4, gpt-5 series, etc.)
|
|
120
|
+
|
|
121
|
+
When using LiteLLM with providers like GitHub Copilot, Anthropic, etc.,
|
|
122
|
+
the Reasoning object causes schema validation errors.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
True if Reasoning parameter should be used, False otherwise
|
|
126
|
+
"""
|
|
127
|
+
# Import here to avoid circular imports
|
|
128
|
+
from .client import is_native_openai_provider
|
|
129
|
+
|
|
130
|
+
# Only use Reasoning parameter when using native OpenAI provider
|
|
131
|
+
# For LiteLLM-based providers (including GitHub Copilot), skip it
|
|
132
|
+
return is_native_openai_provider()
|