Repository navigation
test: unit tests for ToolUseAgent (blocks, StructuredDiscussion, get_action loop) - #55
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…cussion, get_action loop) Co-Authored-By: Daniella Grimberg <daniella@cognition.ai>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Author
There was a problem hiding this comment.
🔍 Devin Review: 2 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
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.
Summary
Adds the first tests for
agentlab.agents.tool_use_agent.tool_use_agentin one new file,tests/agents/test_tool_use_agent_unit.py. Nothing insrc/or any existing test changes. The tests are hermetic: no network, browser, API keys or real sleeps.How the tests are built
FakeModel(payload: APIPayload) -> LLMOutputreturns scriptedLLMOutputs and records each payload. It also providesreset_statsandstats.stats_dict.FakeModelArgs(BaseModelArgs)returns that model plus a realOpenAIResponseAPIMessageBuilderorAnthropicAPIMessageBuilder.FakeActionSet.to_tool_description()stands in for the action set. Some tests use the realbgym.HighLevelActionSet(("coord",))andOSWorldActionSet("computer_13")instead.tmp_path.requests.post,time.sleepandrandom.uniformare monkeypatched, and an autouse fixture resets theTRACKERthread-local.What is covered (72 tests + 2 xfail)
StructuredDiscussion.flatten: groups outside the lastkeep_last_n_obsare replaced by their summary (a group with no summary stays whole). Stale_cache_breakpoints are cleared and exactly one new one is set. Also covers auto group names, the empty/no-goal cases andkeep_last_n_obslarger than the number of groups.Goal: system vs user role for each builder, and text/image/unknown content.Obsand_format_tabs: error, screenshot, SoM, axtree, DOM and tabs parts, and replying "See Observation" to the previous tool calls.GeneralHintsandSummarizer:apply_initwith high and low detail, and the LLM summary call that sets the group summary.TaskHint:direct(fnmatch),llm(topic choice, dedupe, bad answers),emb(loading the.npyfile, top-n through mocked/encodeand/similarity), plus an unknown mode._encode/_similarityretry with backoff, then raise.ToolUseAgentArgs:agent_namederivation,prepare/closepassing through to the model args,make_agentfalling back toDEFAULT_PROMPT_CONFIG,set_benchmark("osworld")turning onskip_preprocessing, and sanity checks on the predefined configs.ToolUseAgent:obs_preprocessor: skip path, page screenshot path, dom/axtree/SoM paths (mocked, plus one run of the realflatten_axtree_to_str).get_action:chat_messagessent to xray (tool description first, tool message last).think.keep_last_n_obs=1replacing old observations with their summaries.Coverage
agentlab.agents.tool_use_agent.tool_use_agentThe one missed line is the
passbody of the abstractBlock.apply.Source bugs found (tests marked
xfail(strict=True),src/not changed)TaskHint.choose_hints_llm: if the LLM answers with valid JSON that is not an int, e.g."1"(quoted),json.loadsreturns a str. The comparisonhint_topic_idx < 0then raises an uncaughtTypeErrorinstead of returning no hints (onlyJSONDecodeErroris caught).TaskHint.encode_hints: the embeddings path isf"{self.hint_db_rel_path}.embs.npy", which is resolved against the current working directory._init, by contrast, resolves the CSV next to the module, so with the default relativehint_db.csvthe embeddings next to that CSV are never found.Run
--cov=agentlab.agents.tool_use_agent.tool_use_agent(the submodule) crashes collection withRuntimeError: function '_has_torch_function' already has a docstring. That form makes coverage import the package before pytest does, so torch ends up imported twice. Pointing--covat the package, as above, avoids it.Also verified: random order (pytest-randomly with 3 seeds),
black --check --line-length 100, and the full suite with-n 4. The full suite shows only the 8 known local failures from missing Chromium/MiniWoB.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/4338d4551ea24ff19719ba133b6b9230
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/4338d4551ea24ff19719ba133b6b9230?variant=devin
Requested by: @danigrim
Devin Review