Skip to content

Commit 58ca021

Browse files
fix: address three robustness findings from #113 (#125)
* fix: close related robustness gaps * docs(progress): record robustness review PR * docs: document branch lanes for repo work
1 parent 1ce7ffe commit 58ca021

14 files changed

Lines changed: 95 additions & 21 deletions

‎AGENTS.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,20 @@ agentkit/
104104
- **Atomic Commits**: One logical change per commit.
105105
- **Branching Strategy**:
106106
- Feature/task branches only: `feat/<slug>`, `fix/<slug>`, `test/<slug>`, `docs/<slug>`, `chore/<slug>`.
107+
- Branch lanes: `develop` is the integration lane, `fix/work-queue` is the starting lane for maintenance fixes, and `feat/roadmap` is the starting lane for feature work. Create a short-lived task branch from the appropriate lane and open its PR against `main`.
107108
- **Never commit directly to `main`** (except the initial warm-up scaffolding push).
108109
- **Never force-push `main`**.
109110
- All task changes must be opened as pull requests and merged via `gh pr merge`.
110111

112+
### Release and tag workflow
113+
- Use Semantic Versioning. Keep `[project].version` in `pyproject.toml` aligned with the latest published release until a release PR proposes the next version.
114+
- Before choosing a version, fetch tags and inspect the current release: `git fetch --tags`, `git tag --sort=-version:refname`, and `gh release view`.
115+
- Bump the version and update release notes in a task branch; run the full quality gates and open a PR. Do not create a release tag before that PR is merged to `main`.
116+
- After merge, verify `main` is current and the version is unused, then create an annotated tag on the merge commit: `git tag -a vX.Y.Z -m "AgentKit vX.Y.Z"`. Push the tag with `git push origin vX.Y.Z` and create the GitHub release with `gh release create vX.Y.Z --verify-tag --generate-notes`.
117+
- For package artifacts, build and inspect before publishing: `python -m pip install build twine`, `python -m build`, and `python -m twine check dist/*`. Confirm the package registry name belongs to this repository and that the publishing identity is configured before any upload; never publish credentials or artifacts from an unreviewed branch.
118+
- Registry check on 2026-11-03 found that PyPI's `agentkit` project metadata identifies a different maintainer and project. Do not upload this repository under that name unless ownership is confirmed; resolve the distribution name and update `pyproject.toml`, install instructions, and the trusted publisher configuration first.
119+
- Never move or reuse a published tag. If a tag already exists, select the next unused version and record the correction in the release PR.
120+
111121
---
112122

113123
## 5. Definition of Done (DoD)

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# AgentKit
22

3+
<img src="docs/assets/agentkit-logo.png" alt="AgentKit logo" width="96">
4+
35
[![CI](https://github.com/getdownandcode/AgentKit/actions/workflows/ci.yml/badge.svg)](https://github.com/getdownandcode/AgentKit/actions/workflows/ci.yml)
46
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
57
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
68

79
AgentKit is a Python service for running tool-using AI agents. A client submits a goal, the agent asks a language model what to do, runs any requested tools, and returns a final answer. Runs and tool steps are recorded so they can be inspected later.
810

9-
The runtime is implemented in this repository rather than delegated to an agent framework. It supports Google Gemini and OpenAI; tests use a fake model client so the normal test suite does not need provider credentials.
11+
The runtime is implemented in this repository rather than delegated to an agent framework. It supports Google Gemini and OpenAI; the default Gemini model is `gemini-3.1-flash-lite`. Tests use a fake model client so the normal test suite does not need provider credentials.
1012

1113
## What happens during a run
1214

@@ -128,7 +130,7 @@ The standard API registry includes these tools:
128130
- `calculator` evaluates arithmetic through a restricted AST evaluator.
129131
- `read_file` reads files under the configured sandbox directory and blocks traversal and symlink escapes.
130132
- `http_fetch` fetches HTTP(S) resources while blocking private, loopback, link-local, and metadata addresses.
131-
- `sql_readonly` runs a single read-only query using a dedicated PostgreSQL role. It fails closed when that role is not configured.
133+
- `sql_readonly` runs a single read-only query using the dedicated PostgreSQL role configured by `DATABASE_READONLY_URL`. It fails closed when that role is not configured.
132134
- `web_search` is included only when `SEARCH_API_KEY` is set.
133135

134136
Tool arguments are validated against JSON Schema derived from Python function annotations. Synchronous tools run outside the event loop; tool results and errors are returned in a structured form.
@@ -181,6 +183,7 @@ def add_numbers(left: int, right: int) -> int:
181183
"""Add two integers."""
182184
return left + right
183185

186+
184187
schema = registry.schemas()[0]
185188
schema.name, schema.parameters
186189
```

‎agentkit/api/ratelimit.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,16 @@ async def check(
9595
Redis is unreachable.
9696
"""
9797
now = time.time()
98-
effective_limit = limit or self.requests_per_window or 30
99-
effective_window = float(window_seconds or self.window_seconds)
98+
effective_limit = (
99+
limit
100+
if limit is not None
101+
else self.requests_per_window
102+
if self.requests_per_window is not None
103+
else 30
104+
)
105+
effective_window = float(
106+
window_seconds if window_seconds is not None else self.window_seconds
107+
)
100108

101109
if redis_client is not None:
102110
redis_key = f"{self.prefix}{key}"
@@ -143,8 +151,11 @@ def _check_window_in_memory(self, key: str, now: float, window: float, limit: in
143151
active_timestamps = [t for t in self._memory_store.get(key, []) if t > now - window]
144152

145153
if len(active_timestamps) >= limit:
146-
oldest_score = active_timestamps[0]
147-
retry_after = max(1, math.ceil(oldest_score + window - now))
154+
retry_after = (
155+
max(1, math.ceil(active_timestamps[0] + window - now))
156+
if active_timestamps
157+
else max(1, math.ceil(window))
158+
)
148159
self._memory_store[key] = active_timestamps
149160
logger.warning(
150161
"In-memory rate limit exceeded for key %s. Retry after: %ds",

‎agentkit/api/routes.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from agentkit.core.agent import Agent
2626
from agentkit.core.errors import PersistenceError, RunNotFoundError
2727
from agentkit.core.trace import StepTrace, TraceSink
28+
from agentkit.core.types import RunStatus
2829
from agentkit.memory.base import MemoryStore
2930
from agentkit.memory.pg_store import PostgresMemoryStore
3031
from agentkit.tools.registry import ToolRegistry
@@ -75,7 +76,7 @@ async def create_run(
7576
run_id=run_record.id,
7677
session_id=run_record.session_id,
7778
goal=run_record.goal,
78-
status=run_record.status,
79+
status=RunStatus(run_record.status),
7980
answer=run_record.final_answer,
8081
failure_reason=run_record.failure_reason,
8182
total_input_tokens=run_record.total_input_tokens,
@@ -90,7 +91,7 @@ async def create_run(
9091
run_id=result.run_id,
9192
session_id=payload.session_id,
9293
goal=payload.goal,
93-
status=result.status.value,
94+
status=result.status,
9495
answer=result.final_answer,
9596
failure_reason=result.failure_reason,
9697
total_input_tokens=result.total_input_tokens,
@@ -117,7 +118,7 @@ async def get_run_details(
117118
run_id=run_record.id,
118119
session_id=run_record.session_id,
119120
goal=run_record.goal,
120-
status=run_record.status,
121+
status=RunStatus(run_record.status),
121122
answer=run_record.final_answer,
122123
failure_reason=run_record.failure_reason,
123124
total_input_tokens=run_record.total_input_tokens,

‎agentkit/api/schemas.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pydantic import BaseModel, ConfigDict, Field
77

8+
from agentkit.core.types import RunStatus
89
from agentkit.db.models import SESSION_ID_MAX_LENGTH
910

1011

@@ -32,7 +33,7 @@ class RunResponse(BaseModel):
3233
run_id: str = Field(..., description="Unique identifier of the run.")
3334
session_id: str | None = Field(default=None, description="Associated session identifier.")
3435
goal: str = Field(..., description="Task objective submitted for this run.")
35-
status: str = Field(..., description="Execution status of the run.")
36+
status: RunStatus = Field(..., description="Execution status of the run.")
3637
answer: str | None = Field(default=None, description="Final answer produced by the agent.")
3738
failure_reason: str | None = Field(
3839
default=None, description="Reason for failure if status is failed or timed_out."

‎agentkit/tools/executor.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
from agentkit.tools.registry import ToolRegistry
1313

1414

15+
def _truncate_output(output: str, max_chars: int) -> str:
16+
"""Keep a truncation notice inside the configured output character budget."""
17+
marker = f"\n[Output truncated: exceeded {max_chars} character limit]"
18+
if max_chars <= len(marker):
19+
return marker[:max_chars]
20+
return output[: max_chars - len(marker)] + marker
21+
22+
1523
async def execute_tool(
1624
registry: "ToolRegistry",
1725
tool_call: ToolCall,
@@ -75,10 +83,7 @@ def get_latency_ms() -> int:
7583
if raw_output.latency_ms == 0:
7684
updates["latency_ms"] = latency_ms
7785
if raw_output.ok and len(raw_output.output) > max_chars:
78-
updates["output"] = (
79-
raw_output.output[:max_chars]
80-
+ f"\n[Output truncated: exceeded {max_chars} character limit]"
81-
)
86+
updates["output"] = _truncate_output(raw_output.output, max_chars)
8287
updates["truncated"] = True
8388
return raw_output.model_copy(update=updates) if updates else raw_output
8489

@@ -87,10 +92,7 @@ def get_latency_ms() -> int:
8792

8893
# Truncate if output exceeds max_chars limit
8994
if len(output_str) > max_chars:
90-
truncated_str = (
91-
output_str[:max_chars]
92-
+ f"\n[Output truncated: exceeded {max_chars} character limit]"
93-
)
95+
truncated_str = _truncate_output(output_str, max_chars)
9496
return ToolResult.success(
9597
truncated_str,
9698
latency_ms=latency_ms,

‎docs/PROGRESS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This document tracks execution progress across all backlog tasks, including pull
44

55
| Task ID | Milestone | Title | Branch | PR # | Commits | Status | Notes & Blockers |
66
|---------|-----------|-------|--------|------|---------|--------|------------------|
7+
| ROADMAP-21 | M16 | Executor output cap, rate-limit zero quota, typed run status | `fix/robustness-odds-and-ends` | [#125](https://github.com/getdownandcode/AgentKit/pull/125) | 3 | In review | Fixes three small robustness items from #113; corrects README claims caught by docs-accuracy tests; aligns package version with latest release tag `v1.0.1`; adds release/tag procedure and logo. Test-suite audit found no unnecessary tests to remove; coverage is 93.57%. Pruned 19 merged remote refs and created `develop`, `fix/work-queue`, and `feat/roadmap` lanes. |
78
| ROADMAP-01/06/07 | M14 | Run cancellation, token accounting, optional search registration | `fix/related-run-tool-hardening` | [#122](https://github.com/getdownandcode/AgentKit/pull/122) | 5 | In review | Fixes #93, #98 and #99 together: canceled runs persist terminal state, turn usage is attributed once across tool traces, and web_search is registered only with SEARCH_API_KEY. Review-fix round: cancellation during the awaited history load (after create_run but before the guarded loop) also finalizes the run as canceled with history untouched (tests/unit/test_agent_cancellation.py, ADR-021), and the real-infra /tools test now pins SEARCH_API_KEY per case so it is deterministic with the key set or unset. Quality gates pass (ruff check/format, mypy agentkit tests, pytest 508 hermetic passed, 31 real-infra passed, pytest-cov 93.4% >= 85%). |
89
| M0-T01 | M0 | Repository Setup & Context Scaffolding | `main` | N/A | 7 | Done | Initial warm-up repository scaffolding |
910
| M0-T02 | M0 | Configuration Management | `feat/config-settings` | #1 | 2 | Done | Pydantic BaseSettings with env validation |

‎docs/assets/agentkit-logo.png‎

400 KB
Loading

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "agentkit"
7-
version = "0.1.0"
7+
version = "1.0.1"
88
description = "A lightweight, provider-agnostic ReAct agent framework in Python built from scratch"
99
readme = "README.md"
1010
requires-python = ">=3.11"

‎tests/unit/test_api_core.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@
33
from pydantic import BaseModel
44

55
from agentkit.api.main import create_app
6+
from agentkit.api.schemas import RunResponse
67
from agentkit.core.errors import ToolNotFoundError, ToolSecurityError
8+
from agentkit.core.types import RunStatus
79

810

911
def test_app_creation() -> None:
1012
app = create_app()
1113
assert app.title == "AgentKit API"
1214

1315

16+
def test_run_response_status_is_a_run_status_enum() -> None:
17+
"""The API boundary should validate statuses and publish their enum values."""
18+
response = RunResponse.model_validate(
19+
{
20+
"run_id": "run-1",
21+
"session_id": None,
22+
"goal": "test",
23+
"status": "succeeded",
24+
"created_at": "2026-01-01T00:00:00Z",
25+
}
26+
)
27+
assert response.status is RunStatus.SUCCEEDED
28+
29+
1430
def test_domain_exception_handler() -> None:
1531
app = create_app()
1632
router = APIRouter()

0 commit comments

Comments
 (0)