Spaces:
Running
Running
Sync provider extra_body runtime
Browse filesFiles changed (2)
- VERSION+1-1
- agent_base/react_agent.py+48-4
1v0.0.461v0.0.47
629 unmodified lines6306316326336346356366376387 unmodified lines64664764864965065175 unmodified lines72772872973073173285 unmodified lines818819820821822823653 unmodified lines147714781479148014811482148341 unmodified lines15251526152715281529153015311532153314 unmodified lines15481549155015511552155311 unmodified lines1565156615671568156915709 unmodified lines1580158115821583158415851586629 unmodified linesreturn textdef default_llm_config(model_name: Optional[str] = None) -> dict:selected_model = str(model_name or "").strip() or default_model_name()return {"model": selected_model,"api_key": os.environ.get("API_KEY", "EMPTY"),"api_base": os.environ.get("API_BASE"),7 unmodified lines"presence_penalty": float(os.environ.get("PRESENCE_PENALTY", str(DEFAULT_PRESENCE_PENALTY))),},}def execute_tool_by_name(tool_map: dict[str, Any], tool_name: str, tool_args: Any, **kwargs):75 unmodified linesraise ValueError('llm["model"] must be a non-empty string.')if "generate_cfg" not in llm or not isinstance(llm["generate_cfg"], dict):raise ValueError('llm["generate_cfg"] must be a dict.')self.tool_map = {tool_name: tool_registry[tool_name] for tool_name in requested_tools}self.tool_names = list(self.tool_map.keys())85 unmodified lineselse self.llm_generate_cfg.get("presence_penalty", 1.1)),)if include_native_tools and self._native_tools:request_kwargs["tools"] = self._native_toolsrequest_kwargs["tool_choice"] = "auto"653 unmodified linesreturn MultiTurnReactAgentdef _parse_cli_args(argv: list[str]) -> tuple[str, Optional[str], Optional[str], str, list[str], list[str], Optional[bool], list[str], list[str]]:parser = argparse.ArgumentParser(description="Run the local agent directly from agent_base.react_agent.")parser.add_argument("prompt", nargs="*", help="Prompt text.")parser.add_argument("--prompt-file", help="Optional UTF-8 text file containing the prompt.")41 unmodified linesmetavar="NAME",help="Expose an explicit complete tool set for this run. May be passed multiple times. Cannot be combined with --extra-tool.",)args = parser.parse_args(argv)if args.tool_names and args.extra_tools:raise ValueError("--tool defines the complete tool set and cannot be combined with --extra-tool.")prompt_text = ""if args.prompt_file:14 unmodified linesargs.chat,validate_named_tools(args.tool_names) if args.tool_names else [],resolve_extra_tool_names(args.extra_tools),)11 unmodified lineschat_arg,tool_names,extra_tools,) = _parse_cli_args(argv or sys.argv[1:])agent_cls = resolve_agent_class_for_role_prompt_files(role_prompt_files)forbidden_tools = set(getattr(agent_cls, "forbidden_tool_names", set()))9 unmodified linesif extra_toolselse None),llm=default_llm_config(),trace_dir=trace_dir,role_prompt=role_prompt or None,)629 unmodified lines6306316326336346356366376386396407 unmodified lines64864965065165265365465565675 unmodified lines73273373473573673773873974074174274374485 unmodified lines830831832833834835836837653 unmodified lines1491149214931494149514961497149814991500150115021503150415051506150715081509151041 unmodified lines15521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157514 unmodified lines159015911592159315941595159611 unmodified lines16081609161016111612161316149 unmodified lines1624162516261627162816291630629 unmodified linesreturn textdef default_llm_config(model_name: Optional[str] = None, extra_body: Optional[dict[str, Any]] = None) -> dict:selected_model = str(model_name or "").strip() or default_model_name()if extra_body is not None and not isinstance(extra_body, dict):raise ValueError("extra_body must be a dict.")config = {"model": selected_model,"api_key": os.environ.get("API_KEY", "EMPTY"),"api_base": os.environ.get("API_BASE"),7 unmodified lines"presence_penalty": float(os.environ.get("PRESENCE_PENALTY", str(DEFAULT_PRESENCE_PENALTY))),},}if extra_body:config["extra_body"] = dict(extra_body)return configdef execute_tool_by_name(tool_map: dict[str, Any], tool_name: str, tool_args: Any, **kwargs):75 unmodified linesraise ValueError('llm["model"] must be a non-empty string.')if "generate_cfg" not in llm or not isinstance(llm["generate_cfg"], dict):raise ValueError('llm["generate_cfg"] must be a dict.')llm_extra_body = llm.get("extra_body")if llm_extra_body is None:self.llm_extra_body: dict[str, Any] = {}elif isinstance(llm_extra_body, dict):self.llm_extra_body = dict(llm_extra_body)else:raise ValueError('llm["extra_body"] must be a dict.')self.tool_map = {tool_name: tool_registry[tool_name] for tool_name in requested_tools}self.tool_names = list(self.tool_map.keys())85 unmodified lineselse self.llm_generate_cfg.get("presence_penalty", 1.1)),)if self.llm_extra_body:request_kwargs["extra_body"] = dict(self.llm_extra_body)if include_native_tools and self._native_tools:request_kwargs["tools"] = self._native_toolsrequest_kwargs["tool_choice"] = "auto"653 unmodified linesreturn MultiTurnReactAgentdef _parse_cli_args(argv: list[str],) -> tuple[str,Optional[str],Optional[str],str,list[str],list[str],Optional[bool],list[str],list[str],dict[str, Any],]:parser = argparse.ArgumentParser(description="Run the local agent directly from agent_base.react_agent.")parser.add_argument("prompt", nargs="*", help="Prompt text.")parser.add_argument("--prompt-file", help="Optional UTF-8 text file containing the prompt.")41 unmodified linesmetavar="NAME",help="Expose an explicit complete tool set for this run. May be passed multiple times. Cannot be combined with --extra-tool.",)parser.add_argument("--llm-extra-body-json",default="",metavar="JSON",help="Provider-specific OpenAI-compatible request extra_body JSON object.",)args = parser.parse_args(argv)if args.tool_names and args.extra_tools:raise ValueError("--tool defines the complete tool set and cannot be combined with --extra-tool.")llm_extra_body: dict[str, Any] = {}if str(args.llm_extra_body_json).strip():try:parsed_extra_body = json.loads(str(args.llm_extra_body_json))except json.JSONDecodeError as exc:raise ValueError("--llm-extra-body-json must be a JSON object.") from excif not isinstance(parsed_extra_body, dict):raise ValueError("--llm-extra-body-json must be a JSON object.")llm_extra_body = parsed_extra_bodyprompt_text = ""if args.prompt_file:14 unmodified linesargs.chat,validate_named_tools(args.tool_names) if args.tool_names else [],resolve_extra_tool_names(args.extra_tools),llm_extra_body,)11 unmodified lineschat_arg,tool_names,extra_tools,llm_extra_body,) = _parse_cli_args(argv or sys.argv[1:])agent_cls = resolve_agent_class_for_role_prompt_files(role_prompt_files)forbidden_tools = set(getattr(agent_cls, "forbidden_tool_names", set()))9 unmodified linesif extra_toolselse None),llm=default_llm_config(extra_body=llm_extra_body),trace_dir=trace_dir,role_prompt=role_prompt or None,)
VERSION+1-1
agent_base/react_agent.py+48-4