1111from datasets import load_dataset
1212
1313from argus import Agent , EverMindMemory
14- from argus .config import Config
14+ from argus .config import AgentConfig , Config , LLMConfig
1515from argus .llm .anthropic import AnthropicClient
1616from argus .llm .base import LLMClient
1717from argus .llm .openai import OpenAIClient
@@ -87,40 +87,52 @@ def _build_task_with_images(instance: dict) -> str | list:
8787 return content
8888
8989
90- def _build_llm (cfg : Config ) -> LLMClient :
91- """Instantiate the LLM client specified by cfg.llm.provider ."""
92- provider = cfg .llm . provider .lower ()
90+ def _build_llm (cfg : LLMConfig ) -> LLMClient :
91+ """Instantiate the LLM client."""
92+ provider = cfg .provider .lower ()
9393 if provider == "anthropic" :
9494 return AnthropicClient (
95- model = cfg .llm . model ,
96- api_key = cfg .llm . api_key ,
97- base_url = cfg .llm . base_url or None ,
98- temperature = cfg .llm . temperature ,
95+ model = cfg .model ,
96+ api_key = cfg .api_key ,
97+ base_url = cfg .base_url or None ,
98+ temperature = cfg .temperature ,
9999 )
100100 if provider == "openai" :
101101 return OpenAIClient (
102- model = cfg .llm . model ,
103- api_key = cfg .llm . api_key ,
104- base_url = cfg .llm . base_url or None ,
105- temperature = cfg .llm . temperature ,
102+ model = cfg .model ,
103+ api_key = cfg .api_key ,
104+ base_url = cfg .base_url or None ,
105+ temperature = cfg .temperature ,
106106 )
107- raise ValueError (f"Unknown LLM provider: { cfg .llm . provider !r} . Supported: openai, anthropic" )
107+ raise ValueError (f"Unknown LLM provider: { cfg .provider !r} . Supported: openai, anthropic" )
108108
109109
110- def _build_agent (
111- cfg : Config , llm : LLMClient , instance : dict , memory : EverMindMemory | None
112- ) -> tuple [Agent , ShellTool ]:
110+ def _build_agent (cfg : AgentConfig , instance : dict ) -> Agent :
111+ """Instantiate the agent with the appropriate tools, LLM, and memory (if enabled)."""
113112 shell = ShellTool (_docker_image (instance ), workdir = "/testbed" , remove_on_cleanup = False )
114- log_dir = Path (cfg .agent .log_dir ) / instance ["instance_id" ] if cfg .agent .log_dir else None
113+ log_dir = Path (cfg .log_dir ) / instance ["instance_id" ] if cfg .log_dir else None
114+ llm = _build_llm (cfg .LLM )
115+
116+ if cfg .enable_memory :
117+ memory = EverMindMemory (
118+ user_id = cfg .Memory .user_id ,
119+ base_url = cfg .Memory .base_url ,
120+ api_key = cfg .Memory .api_key ,
121+ retrieve_method = cfg .Memory .retrieve_method ,
122+ top_k = cfg .Memory .top_k ,
123+ )
124+ else :
125+ memory = None
126+
115127 agent = Agent (
116128 llm = llm ,
117129 tools = [shell ],
118- system_prompt = cfg .agent . system_prompt ,
119- max_steps = cfg .agent . max_steps ,
130+ system_prompt = cfg .system_prompt ,
131+ max_steps = cfg .max_steps ,
120132 log_dir = log_dir ,
121133 memory = memory ,
122134 )
123- return agent , shell
135+ return agent
124136
125137
126138def main () -> None :
@@ -137,18 +149,6 @@ def main() -> None:
137149
138150 cfg = Config .from_yaml (Path (__file__ ).parent / args .config )
139151
140- llm = _build_llm (cfg )
141-
142- memory = None
143- if cfg .agent .enable_memory :
144- memory = EverMindMemory (
145- user_id = cfg .memory .user_id ,
146- base_url = cfg .memory .base_url ,
147- api_key = cfg .memory .api_key ,
148- retrieve_method = cfg .memory .retrieve_method ,
149- top_k = cfg .memory .top_k ,
150- )
151-
152152 dataset = load_dataset (DATASET_NAME , split = args .split )
153153 if args .instance_ids :
154154 keep = set (args .instance_ids )
@@ -160,7 +160,7 @@ def main() -> None:
160160 instance_id = instance ["instance_id" ]
161161 logger .info ("=== %s ===" , instance_id )
162162
163- agent , shell = _build_agent (cfg , llm , instance , memory )
163+ agent = _build_agent (cfg . agent , instance )
164164 agent .run (_build_task_with_images (instance ))
165165
166166
0 commit comments