Skip to content

Dynamo/transport refactor - #2

Merged
DYNAMOatGHUB merged 3 commits into
aishafrom
dynamo/transport-refactor
Oct 12, 2026
Merged

DYNAMOatGHUB merged 3 commits into
aishafrom
dynamo/transport-refactor

Conversation

@DYNAMOatGHUB

Copy link
Copy Markdown
Owner

No description provided.

aishaamna9b-art and others added 3 commits October 7, 2026 09:14
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>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@DYNAMOatGHUB
DYNAMOatGHUB merged commit 33e32b5 into aisha Oct 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants