Make loom.agent importable without a contract package - #1
Open
Arunima1405 wants to merge 1 commit into
Open
Conversation
`loom.agent.task_gen` imported `graphite.ContractException` at module import time, so `from loom.agent import AgentLoop` raised ImportError on a plain `pip install loom-workflow` — Loom declares no graphite dependency, and contracts live outside this package by design. The contract-failure shape is now duck-typed, which keeps the same feedback text without the import. Also import `Path` in `loom.agent.agent`, where it was used in an annotation but never imported (`get_type_hints(AgentContext.draft.fget)` raised NameError), and point the README at the agent example's current home in the Graphite repository.
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.
Problem
Three defects found while building an end-to-end example of
AgentLoopagainst a failing contract (companion PR in the Graphite repository). Two
are import bugs; both were reproduced before fixing.
1.
loom.agentcannot be imported from a clean installloom/agent/task_gen.pydidfrom graphite import ContractExceptionatmodule scope, and
loom/agent/__init__.pyimportstask_gen. Loom declaresno graphite dependency —
pyproject.tomllistspydanticandpydantic-ai— and the README states that Graph-IR support and Contracts live in the
separate Graphite package. So after
pip install loom-workflow:loom.coreimports fine; the whole agent half of the package isunreachable. Reproduced by blocking
graphiteonsys.meta_path.The import existed only to recognise a contract failure inside
TaskGen._prompt. That is now duck-typed:ContractException.failuresis alreadydict[str, ContractResult], so therendered feedback is byte-identical for a real
ContractException, and anon-contract exception still renders as
Task/runtime exception: ...exactly as before.
_promptbecomes aclassmethodto reach the helper;its signature and output are otherwise unchanged.
This also restores the architecture the README describes — Loom core stays
domain-neutral and requires no graph, IR, or contract package — and keeps
Provider/TaskGenusable by a caller whose contracts come from somewhereother than Graphite.
2.
Pathused in an annotation but never importedloom/agent/agent.pyannotatesAgentContext.draftasMapping[str, Path]with no
from pathlib import Path.from __future__ import annotationsdefers it, so it stays hidden until something resolves the annotation:
One-line fix.
3. Stale example reference
examples/agentmoved to the Graphite repository ineedcb52, but theREADME still described it as living here, and still told the reader to
uncomment lines by hand to reach the successful task. It now points at
Graphite, where the example runs the loop through the contract failure to
convergence rather than stopping at it.
What is deliberately not here
Bug fixes only — no new abstractions, no new dependencies, no behaviour
change to
AgentLoop,PipelineRunner, orProvider. The example itself,including the agents that drive the loop, lives in the companion Graphite PR
so it stays out of this package.
Verification
With
graphiteblocked onsys.meta_path:Downstream, the Graphite example's
pytest examples/agent/test_agent_loop.pypasses 3/3 against this branch.