MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / construct_agent

Function construct_agent

eval_heldout/webarena/agent/agent.py:247–271  ·  view source on GitHub ↗
(args: argparse.Namespace)

Source from the content-addressed store, hash-verified

245
246
247def construct_agent(args: argparse.Namespace) -> Agent:
248 llm_config = construct_llm_config(args)
249
250 agent: Agent
251 if args.agent_type == "teacher_forcing":
252 agent = TeacherForcingAgent()
253 elif args.agent_type == "prompt":
254 with open(args.instruction_path) as f:
255 constructor_type = json.load(f)["meta_data"]["prompt_constructor"]
256 if llm_config.provider in {'llama'}:
257 tokenizer = tiktoken.encoding_for_model('gpt-4')
258 else: tokenizer = tiktoken.encoding_for_model(llm_config.model)
259 prompt_constructor = eval(constructor_type)(
260 args.instruction_path, lm_config=llm_config, tokenizer=tokenizer
261 )
262 agent = PromptAgent(
263 action_set_tag=args.action_set_tag,
264 lm_config=llm_config,
265 prompt_constructor=prompt_constructor,
266 )
267 else:
268 raise NotImplementedError(
269 f"agent type {args.agent_type} not implemented"
270 )
271 return agent

Callers 1

run.pyFile · 0.90

Calls 5

construct_llm_configFunction · 0.85
TeacherForcingAgentClass · 0.85
evalFunction · 0.85
PromptAgentClass · 0.85
loadMethod · 0.45

Tested by

no test coverage detected