Repository navigation
feature: improve agent code reusability by extracting shared boilerplate - #12
Draft
devin-ai-integration[bot] wants to merge 1 commit into
Draft
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Extract duplicated get_action epilogue (LLM stats + AgentInfo construction and the parse-failure fallback dict) into reusable helpers in agent_utils, and add a ChatModelAgentArgs base providing the shared prepare/close server delegation. GenericAgent, VisualAgent, MostBasicAgent and VisualWebArenaAgent now reuse these instead of copy-pasting them. Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Removes copy-pasted boilerplate that was duplicated across the chat-based agents in
src/agentlab/agents/. Behavior is unchanged — this is a pure refactor to centralize reusable logic, validated against the existing agent test suite.Two sources of duplication were consolidated:
1. The
get_actionepilogue —GenericAgentandVisualAgenthad byte-for-byte identical code to build retry stats +AgentInfo, and to produce the parse-failure fallback dict. Extracted intoagents/agent_utils.py:So each agent's
get_actioncollapses from ~15 lines to:2.
prepare()/close()— these 4×-identical methods (return self.chat_model_args.{prepare,close}_server()) moved into a newChatModelAgentArgs(AgentArgs)base inagents/agent_args.py.GenericAgentArgs,VisualAgentArgs,MostBasicAgentArgs, andVisualWebArenaAgentArgsnow inherit it and drop their own copies.Scope notes
Deliberately left out to avoid behavior changes:
ToolUseAgentArgsusesmodel_args(notchat_model_args), so it keeps its ownprepare/close.TapeAgentArgs/DebugAgentArgshave no LLM server and rely on the no-opprepare/closefrom the base — the new base is opt-in, so they are unaffected. The shared methods were intentionally not added toAgentArgsitself (which would have broken these two).ChatModelAgentArgsdeclares no new dataclass fields, so subclass field ordering / positional construction is preserved.Testing
tests/agents/test_agent_utils.pycoversmake_agent_info,busted_retry_ans_dict, andChatModelAgentArgs.prepare/closedelegation.tests/agents/suite passes (24 passed, 1 skipped) against the MiniWoB server, confirmingGenericAgentend-to-end behavior is preserved.black src/(pinned 25.1.0) anddarglintclean on changed files.Link to Devin session: https://app.devin.ai/sessions/5bea0615dcb648abb0e44224fac5c507
Requested by: @dr-phil
Devin Review