Spaces:
Running
Running
Sync runtime token budget settings
Browse filesFiles changed (7)
1v0.0.481v0.0.49
16 unmodified lines171819202122232418 unmodified lines4344454647484950515253545556575859606126 unmodified lines888990919216 unmodified lines@propertydef compact_trigger_tokens(self) -> int:if self.compact_trigger_tokens_override is not None:return self.compact_trigger_tokens_overridereturn max(256, self.context_window - self.output_reserve_tokens - self.compact_buffer_tokens)def _model_family(model_name: str) -> str:18 unmodified lines*,configured_max_input_tokens: int,configured_max_output_tokens: int,compact_trigger_tokens: Any = None,) -> ModelProfile:context_window = max(1024, int(configured_max_input_tokens))output_reserve_tokens = max(128, min(int(configured_max_output_tokens), max(256, context_window // 12)))compact_buffer_tokens = max(64, min(4096, context_window // 20))recent_history_budget_tokens = max(128, min(16384, context_window // 8))compact_summary_max_tokens = max(256, min(2048, context_window // 16))compact_trigger_override = parse_compact_trigger_tokens(compact_trigger_tokens, context_window=context_window)family = _model_family(model_name)if family in {"claude", "deepseek", "gemini"}:compact_buffer_tokens = max(compact_buffer_tokens, 1024)recent_history_budget_tokens = max(recent_history_budget_tokens, 1024)return ModelProfile(family=family,26 unmodified linestext = text[:-1].strip()text = text.replace("_", "").replace(",", "")parsed = int(text) * multiplierparsed = max(256, parsed)return min(parsed, max(256, int(context_window)))16 unmodified lines17181920212223242526272829303118 unmodified lines5051525354555657585960616263646566676869707172737475767778798081828384858626 unmodified lines11311411511616 unmodified lines@propertydef compact_trigger_tokens(self) -> int:if self.compact_trigger_tokens_override is not None:if self.compact_trigger_tokens_override <= 0:raise ValueError("compact_trigger_tokens must be positive.")return self.compact_trigger_tokens_overridetrigger_tokens = self.context_window - self.output_reserve_tokens - self.compact_buffer_tokensif trigger_tokens <= 0:raise ValueError("max_input_tokens must be larger than max_output_tokens + compact_summary_max_tokens.")return trigger_tokensdef _model_family(model_name: str) -> str:18 unmodified lines*,configured_max_input_tokens: int,configured_max_output_tokens: int,configured_recent_history_budget_tokens: int,configured_compact_summary_max_tokens: int,compact_trigger_tokens: Any = None,) -> ModelProfile:context_window = int(configured_max_input_tokens)if context_window <= 0:raise ValueError("max_input_tokens must be positive.")output_reserve_tokens = int(configured_max_output_tokens)if output_reserve_tokens <= 0:raise ValueError("max_output_tokens must be positive.")if output_reserve_tokens >= context_window:raise ValueError("max_output_tokens must be smaller than max_input_tokens.")recent_history_budget_tokens = int(configured_recent_history_budget_tokens)if recent_history_budget_tokens <= 0:raise ValueError("recent_history_budget_tokens must be positive.")compact_summary_max_tokens = int(configured_compact_summary_max_tokens)if compact_summary_max_tokens <= 0:raise ValueError("compact_summary_max_tokens must be positive.")if output_reserve_tokens + compact_summary_max_tokens >= context_window:raise ValueError("max_output_tokens + compact_summary_max_tokens must be smaller than max_input_tokens.")compact_buffer_tokens = compact_summary_max_tokenscompact_trigger_override = parse_compact_trigger_tokens(compact_trigger_tokens, context_window=context_window)if compact_trigger_override is not None:if compact_trigger_override <= 0:raise ValueError("compact_trigger_tokens must be positive.")if compact_trigger_override >= context_window - output_reserve_tokens:raise ValueError("compact_trigger_tokens must be smaller than max_input_tokens - max_output_tokens.")family = _model_family(model_name)return ModelProfile(family=family,26 unmodified linestext = text[:-1].strip()text = text.replace("_", "").replace(",", "")parsed = int(text) * multiplierreturn parsed
67 unmodified lines68697071727374757677787980561 unmodified lines642643644645646647378 unmodified lines102610271028102910301031103210331034103510361037103867 unmodified lines]OPTIONAL_TOOL_MAP = {tool.name: tool for tool in OPTIONAL_TOOLS}ALL_TOOL_MAP = {**AVAILABLE_TOOL_MAP, **OPTIONAL_TOOL_MAP}DEFAULT_IMAGE_TOKEN_ESTIMATE = 1536DEFAULT_MODEL_NAME = "gpt-5.5"DEFAULT_MAX_ROUNDS = 500DEFAULT_MAX_RUNTIME_SECONDS = 10800DEFAULT_MAX_OUTPUT_TOKENS = 40960DEFAULT_MAX_INPUT_TOKENS = 128000DEFAULT_MAX_RETRIES = 10DEFAULT_TEMPERATURE = 0.6DEFAULT_TOP_P = 0.95DEFAULT_PRESENCE_PENALTY = 1.00561 unmodified lines"generate_cfg": {"max_input_tokens": int(os.environ.get("MAX_INPUT_TOKENS", str(DEFAULT_MAX_INPUT_TOKENS))),"max_output_tokens": int(os.environ.get("MAX_OUTPUT_TOKENS", str(DEFAULT_MAX_OUTPUT_TOKENS))),"max_retries": int(os.environ.get("MAX_RETRIES", str(DEFAULT_MAX_RETRIES))),"temperature": float(os.environ.get("TEMPERATURE", str(DEFAULT_TEMPERATURE))),"top_p": float(os.environ.get("TOP_P", str(DEFAULT_TOP_P))),378 unmodified linesmessages = [{"role": "system", "content": system_prompt}, {"role": "user", "content": user_content}]max_input_tokens = int(self.llm_generate_cfg.get("max_input_tokens", DEFAULT_MAX_INPUT_TOKENS))max_output_tokens = int(self.llm_generate_cfg.get("max_output_tokens", max_output_tokens_default()))compact_trigger_tokens = self.llm_generate_cfg.get("compact_trigger_tokens")if compact_trigger_tokens is None:compact_trigger_tokens = os.getenv("COMPACT_TRIGGER_TOKENS", "96k")model_profile = resolve_model_profile(self.model,configured_max_input_tokens=max_input_tokens,configured_max_output_tokens=max_output_tokens,compact_trigger_tokens=compact_trigger_tokens,)agent_runtime_limit = self.max_runtime_seconds67 unmodified lines686970717273747576777879808182561 unmodified lines644645646647648649650651652653654655378 unmodified lines10341035103610371038103910401041104210431044104510461047104810491050105110521053105467 unmodified lines]OPTIONAL_TOOL_MAP = {tool.name: tool for tool in OPTIONAL_TOOLS}ALL_TOOL_MAP = {**AVAILABLE_TOOL_MAP, **OPTIONAL_TOOL_MAP}DEFAULT_IMAGE_TOKEN_ESTIMATE = 2 * 1024DEFAULT_MODEL_NAME = "gpt-5.5"DEFAULT_MAX_ROUNDS = 500DEFAULT_MAX_RUNTIME_SECONDS = 10800DEFAULT_MAX_OUTPUT_TOKENS = 16 * 1024DEFAULT_MAX_INPUT_TOKENS = 128 * 1024DEFAULT_RECENT_HISTORY_BUDGET_TOKENS = 8 * 1024DEFAULT_COMPACT_SUMMARY_MAX_TOKENS = 8 * 1024DEFAULT_MAX_RETRIES = 5DEFAULT_TEMPERATURE = 0.6DEFAULT_TOP_P = 0.95DEFAULT_PRESENCE_PENALTY = 1.00561 unmodified lines"generate_cfg": {"max_input_tokens": int(os.environ.get("MAX_INPUT_TOKENS", str(DEFAULT_MAX_INPUT_TOKENS))),"max_output_tokens": int(os.environ.get("MAX_OUTPUT_TOKENS", str(DEFAULT_MAX_OUTPUT_TOKENS))),"recent_history_budget_tokens": int(os.environ.get("RECENT_HISTORY_BUDGET_TOKENS", str(DEFAULT_RECENT_HISTORY_BUDGET_TOKENS))),"compact_summary_max_tokens": int(os.environ.get("COMPACT_SUMMARY_MAX_TOKENS", str(DEFAULT_COMPACT_SUMMARY_MAX_TOKENS))),"max_retries": int(os.environ.get("MAX_RETRIES", str(DEFAULT_MAX_RETRIES))),"temperature": float(os.environ.get("TEMPERATURE", str(DEFAULT_TEMPERATURE))),"top_p": float(os.environ.get("TOP_P", str(DEFAULT_TOP_P))),378 unmodified linesmessages = [{"role": "system", "content": system_prompt}, {"role": "user", "content": user_content}]max_input_tokens = int(self.llm_generate_cfg.get("max_input_tokens", DEFAULT_MAX_INPUT_TOKENS))max_output_tokens = int(self.llm_generate_cfg.get("max_output_tokens", max_output_tokens_default()))recent_history_budget_tokens = int(self.llm_generate_cfg.get("recent_history_budget_tokens", DEFAULT_RECENT_HISTORY_BUDGET_TOKENS))compact_summary_max_tokens = int(self.llm_generate_cfg.get("compact_summary_max_tokens", DEFAULT_COMPACT_SUMMARY_MAX_TOKENS))compact_trigger_tokens = self.llm_generate_cfg.get("compact_trigger_tokens")if compact_trigger_tokens is None:compact_trigger_tokens = os.getenv("COMPACT_TRIGGER_TOKENS")model_profile = resolve_model_profile(self.model,configured_max_input_tokens=max_input_tokens,configured_max_output_tokens=max_output_tokens,configured_recent_history_budget_tokens=recent_history_budget_tokens,configured_compact_summary_max_tokens=compact_summary_max_tokens,compact_trigger_tokens=compact_trigger_tokens,)agent_runtime_limit = self.max_runtime_seconds
7 unmodified lines891011121314151617187 unmodified linesfrom typing import Any, Optional, Unionfrom xml.etree import ElementTreefrom agent_base.tools.tool_file import ReadPDFfrom agent_base.tools.tooling import ToolBase, validate_tool_pathDEFAULT_EDITOR_MAX_CHARS = 20000BINARY_MARKDOWN_SUFFIXES = {".xlsx", ".pptx", ".wav", ".mp3", ".m4a", ".flac", ".pdf", ".docx"}7 unmodified lines891011121314151617187 unmodified linesfrom typing import Any, Optional, Unionfrom xml.etree import ElementTreefrom agent_base.tools.tool_file import DEFAULT_LOCAL_MAX_CHARS, ReadPDFfrom agent_base.tools.tooling import ToolBase, validate_tool_pathDEFAULT_EDITOR_MAX_CHARS = DEFAULT_LOCAL_MAX_CHARSBINARY_MARKDOWN_SUFFIXES = {".xlsx", ".pptx", ".wav", ".mp3", ".m4a", ".flac", ".pdf", ".docx"}
28 unmodified lines29303132333435363748 unmodified lines8687888990919214 unmodified lines10710810911011111211358 unmodified lines17217317417517617717814 unmodified lines193194195196197198199356 unmodified lines556557558559560561562280 unmodified lines84384484584684784884985085185285328 unmodified linesDEFAULT_LLM_IMAGE_JPEG_QUALITY = 85MIN_LLM_IMAGE_JPEG_QUALITY = 45MIN_LLM_IMAGE_EDGE = 256DEFAULT_GLOB_MAX_RESULTS = 200DEFAULT_GREP_MAX_RESULTS = 100DEFAULT_GREP_MAX_CHARS = 20000def resolve_file_path(path_value: str, *, base_root: Optional[Path] = None) -> Path:48 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 20000.",},},"required": ["path"],14 unmodified linesstart_line_raw = params.get("start_line", 1)end_line_raw = params.get("end_line")max_chars_raw = params.get("max_chars", 20000)try:start_line = int(start_line_raw)end_line = end_line_raw58 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 20000.",},"max_image_paths": {"type": "integer",14 unmodified linesbase_root = kwargs.get("workspace_root")try:max_chars = int(params.get("max_chars", 20000))max_image_paths = int(params.get("max_image_paths", 20))except (TypeError, ValueError):return "[ReadPDF] max_chars and max_image_paths must be integers."356 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 20000.",},},"required": ["pattern"],280 unmodified linesread_parser.add_argument("path")read_parser.add_argument("--start-line", type=int, default=1)read_parser.add_argument("--end-line", type=int)read_parser.add_argument("--max-chars", type=int, default=20000)pdf_parser = subparsers.add_parser("pdf", help="Run ReadPDF on a PDF file.")pdf_parser.add_argument("path")pdf_parser.add_argument("--max-chars", type=int, default=20000)image_parser = subparsers.add_parser("image", help="Run ReadImage on an image file.")image_parser.add_argument("path")28 unmodified lines2930313233343536373848 unmodified lines8788899091929314 unmodified lines10810911011111211311458 unmodified lines17317417517617717817914 unmodified lines194195196197198199200356 unmodified lines557558559560561562563280 unmodified lines84484584684784884985085185285385428 unmodified linesDEFAULT_LLM_IMAGE_JPEG_QUALITY = 85MIN_LLM_IMAGE_JPEG_QUALITY = 45MIN_LLM_IMAGE_EDGE = 256DEFAULT_LOCAL_MAX_CHARS = 8192DEFAULT_GLOB_MAX_RESULTS = 200DEFAULT_GREP_MAX_RESULTS = 100DEFAULT_GREP_MAX_CHARS = DEFAULT_LOCAL_MAX_CHARSdef resolve_file_path(path_value: str, *, base_root: Optional[Path] = None) -> Path:48 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 8192.",},},"required": ["path"],14 unmodified linesstart_line_raw = params.get("start_line", 1)end_line_raw = params.get("end_line")max_chars_raw = params.get("max_chars", DEFAULT_LOCAL_MAX_CHARS)try:start_line = int(start_line_raw)end_line = end_line_raw58 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 8192.",},"max_image_paths": {"type": "integer",14 unmodified linesbase_root = kwargs.get("workspace_root")try:max_chars = int(params.get("max_chars", DEFAULT_LOCAL_MAX_CHARS))max_image_paths = int(params.get("max_image_paths", 20))except (TypeError, ValueError):return "[ReadPDF] max_chars and max_image_paths must be integers."356 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 8192.",},},"required": ["pattern"],280 unmodified linesread_parser.add_argument("path")read_parser.add_argument("--start-line", type=int, default=1)read_parser.add_argument("--end-line", type=int)read_parser.add_argument("--max-chars", type=int, default=DEFAULT_LOCAL_MAX_CHARS)pdf_parser = subparsers.add_parser("pdf", help="Run ReadPDF on a PDF file.")pdf_parser.add_argument("path")pdf_parser.add_argument("--max-chars", type=int, default=DEFAULT_LOCAL_MAX_CHARS)image_parser = subparsers.add_parser("image", help="Run ReadImage on an image file.")image_parser.add_argument("path")
26 unmodified lines27282930313233500 unmodified lines53453553653753853954055 unmodified lines59659759859960060160289 unmodified lines69269369469569669769826 unmodified linesDEFAULT_BUFFER_LIMIT = 200000DEFAULT_OUTPUT_CHARS = 20000DEFAULT_YIELD_MS = 200REPEAT_COLLAPSE_THRESHOLD = 3500 unmodified lines},"max_output_chars": {"type": "integer","description": "Maximum number of output characters to return. Default is 20000.",},},"required": ["session_id", "input"],55 unmodified lines},"max_output_chars": {"type": "integer","description": "Maximum number of output characters to return. Default is 20000.",},},"required": ["session_id"],89 unmodified lines},"max_output_chars": {"type": "integer","description": "Maximum number of output characters to return after the interrupt. Default is 20000.",},},"required": ["session_id"],26 unmodified lines27282930313233500 unmodified lines53453553653753853954055 unmodified lines59659759859960060160289 unmodified lines69269369469569669769826 unmodified linesDEFAULT_BUFFER_LIMIT = 200000DEFAULT_OUTPUT_CHARS = 8192DEFAULT_YIELD_MS = 200REPEAT_COLLAPSE_THRESHOLD = 3500 unmodified lines},"max_output_chars": {"type": "integer","description": f"Maximum number of output characters to return. Default is {DEFAULT_OUTPUT_CHARS}.",},},"required": ["session_id", "input"],55 unmodified lines},"max_output_chars": {"type": "integer","description": f"Maximum number of output characters to return. Default is {DEFAULT_OUTPUT_CHARS}.",},},"required": ["session_id"],89 unmodified lines},"max_output_chars": {"type": "integer","description": f"Maximum number of output characters to return after the interrupt. Default is {DEFAULT_OUTPUT_CHARS}.",},},"required": ["session_id"],
10 unmodified lines11121314151617256 unmodified lines27427527627727827928010 unmodified linesfrom agent_base.utils import PROJECT_ROOT, env_flag, load_dotenvDEFAULT_WEBFETCH_TIMEOUT_SECONDS = 300.0DEFAULT_WEBFETCH_MAX_CHARS = 40960def webfetch_timeout_seconds() -> float:256 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 40960 and the value must not exceed WEBFETCH_MAX_CHARS.",},},"required": ["url"],10 unmodified lines11121314151617256 unmodified lines27427527627727827928010 unmodified linesfrom agent_base.utils import PROJECT_ROOT, env_flag, load_dotenvDEFAULT_WEBFETCH_TIMEOUT_SECONDS = 300.0DEFAULT_WEBFETCH_MAX_CHARS = 8192def webfetch_timeout_seconds() -> float:256 unmodified lines},"max_chars": {"type": "integer","description": "Maximum number of characters to return. Default is 8192 and the value must not exceed WEBFETCH_MAX_CHARS.",},},"required": ["url"],
VERSION+1-1
agent_base/model_profiles.py+35-11
agent_base/react_agent.py+21-5
agent_base/tools/tool_extra.py+2-2
agent_base/tools/tool_file.py+9-8
agent_base/tools/tool_runtime.py+4-4
agent_base/tools/tool_web.py+2-2