Repository navigation
Dynamo/transport refactor - #2
Merged
Merged
Conversation
Adds pipeline Step 3 (PRD-02) on top of the existing reflection, prompt,
and orchestration layers.
Implemented
-----------
tinyagent/backends/base.py
- Shared stdlib-only HTTP transport (urllib) posting one UTF-8 JSON
request per call, with no streaming.
- Maps every failure to a typed BackendError:
E_BACKEND_UNREACHABLE, E_BACKEND_TIMEOUT, E_BACKEND_HTTP,
E_BACKEND_PROTOCOL.
- Redacts prompt text from error details; details are kept to a
single line of at most 200 chars.
- Validates call arguments (prompt type, max_tokens 1..512, stop list).
- Detects loopback hosts (localhost, 127/8, ::1).
tinyagent/backends/ollama.py
- OllamaBackend -> POST /api/generate with greedy, seeded decoding
(temperature 0, top_k 1, top_p 1), num_predict, stop and optional
num_ctx. Surfaces Ollama's "error" field as E_BACKEND_HTTP.
tinyagent/backends/llamacpp.py
- LlamaCppBackend -> POST /completion with the same decoding settings,
n_predict, stop and cache_prompt.
- Both backends warn when the host is not loopback and report latency
and prompt/completion token counts.
Tests
-----
- tests/stub_server.py: threaded local HTTP stub server.
- tests/test_backends.py: 13 tests covering the request contract,
token counts, HTTP/timeout/unreachable mapping, prompt redaction,
protocol errors and fuzzing with 50 malformed responses.
- tests/fixtures/ollama_generate.json: a real Ollama response.
Status
------
- Code is imported unchanged from the working copy. 2 of the 13
backend tests fail because of defects in the tests themselves; the
next commit fixes them.
- parser.py, executor.py and coercion.py (PRD-03) are still pending,
so the CLI and eval runner cannot run end to end yet.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code is cleaner and behavior is unchanged. Net -27 lines across 10 files.
Refactoring
-----------
backends/base.py
- Replace five near-duplicate exception handlers in _post_json with
two: HTTPError -> E_BACKEND_HTTP; everything else -> timeout or
unreachable (URLError is unwrapped via .reason).
- Route invalid-JSON and non-object responses through the existing
_protocol_error helper; remove the redundant _raise_backend_error
and the now-unused BACKEND_CODES import.
backends/ollama.py
- Reuse _single_line for server-error redaction instead of an inline
copy of the same logic; add full type hints to complete().
backends/llamacpp.py
- Remove a duplicate Completion import inside complete(); add type
hints.
agent.py
- Build all five AgentResult exit paths through one finish() helper
instead of repeating seven positional arguments each time. The
imports inside run() stay because the agent tests stub those
modules through sys.modules.
reflection.py
- Raise the unsupported-type error from one place instead of two.
- Extract _describe() for docstring -> description; name the
rejected parameter kinds in _UNSUPPORTED_KINDS.
prompt.py
- Shorten _sanitize; extract _render_default(); simplify the
"(none)" tool-list fallback.
registry.py / types.py / errors.py
- Use the builtin tuple instead of typing.Tuple; PEP 8 blank lines;
remove trailing whitespace.
Test fixes (tests/test_backends.py)
-----------------------------------
- test_ollama_request_contract required the header key
"Content-type" exactly. urllib sends "Content-Type" on Python 3.13
and other casing on older versions, so the check now ignores case.
- test_http_error_precedes_url_error_mapping expected
`status - 403` requests, which comes to 97 for a 500 response. It
now expects one request per subtest so far.
Verification
------------
- unittest: 48/48 pass (was 46/48).
- _sanitize, render_tool_line, render_prompt, type-hint parsing and
tiny_tool descriptions give identical output to the previous commit
on ~6000 generated inputs.
Status after this commit
------------------------
- Unchanged: tinyagent/parser.py, executor.py and coercion.py
(PRD-03) are still missing, so the CLI and eval runner still fail
with ModuleNotFoundError. These are feature work, not part of this
refactor.
- README.md says the transport has not landed, but
tinyagent/backends/ is implemented and tested. The README should be
updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.