Spaces:
Running
Running
Sync runtime token budget settings
Browse filesFiles changed (7)
11v0.0.48v0.0.4916 unmodified lines1718192021222123242526272829303118 unmodified lines50515253545556484950515257585960616263646566676869707172737475767778798081828356575884858626 unmodified lines113114115919211616 unmodified lines @property def 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_override return max(256, self.context_window - self.output_reserve_tokens - self.compact_buffer_tokens) trigger_tokens = self.context_window - self.output_reserve_tokens - self.compact_buffer_tokens if trigger_tokens <= 0: raise ValueError( "max_input_tokens must be larger than max_output_tokens + compact_summary_max_tokens." ) return trigger_tokens
def _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 = 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)) 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_tokens compact_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) 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 lines text = text[:-1].strip() text = text.replace("_", "").replace(",", "") parsed = int(text) * multiplier parsed = max(256, parsed) return min(parsed, max(256, int(context_window))) return parsed67 unmodified lines68697071717273747576777576777879808182561 unmodified lines644645646647648649650651652653654655378 unmodified lines103410351036103710381039104010411042104310441031104510461047104810491050105110521053105467 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_IMAGE_TOKEN_ESTIMATE = 2 * 1024DEFAULT_MODEL_NAME = "gpt-5.5"DEFAULT_MAX_ROUNDS = 500DEFAULT_MAX_RUNTIME_SECONDS = 10800DEFAULT_MAX_OUTPUT_TOKENS = 40960DEFAULT_MAX_INPUT_TOKENS = 128000DEFAULT_MAX_RETRIES = 10DEFAULT_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 lines messages = [{"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", "96k") 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_seconds7 unmodified lines8910111112131415151617187 unmodified linesfrom typing import Any, Optional, Unionfrom xml.etree import ElementTree
from agent_base.tools.tool_file import ReadPDFfrom agent_base.tools.tool_file import DEFAULT_LOCAL_MAX_CHARS, ReadPDFfrom agent_base.tools.tooling import ToolBase, validate_tool_path
DEFAULT_EDITOR_MAX_CHARS = 20000DEFAULT_EDITOR_MAX_CHARS = DEFAULT_LOCAL_MAX_CHARSBINARY_MARKDOWN_SUFFIXES = {".xlsx", ".pptx", ".wav", ".mp3", ".m4a", ".flac", ".pdf", ".docx"}
28 unmodified lines293031323334343536373848 unmodified lines878889899091929314 unmodified lines10810911011011111211311458 unmodified lines17317417517517617717817914 unmodified lines194195196196197198199200356 unmodified lines557558559559560561562563280 unmodified lines84484584684684784884985085085185285385428 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 = 20000DEFAULT_GREP_MAX_CHARS = DEFAULT_LOCAL_MAX_CHARS
def 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.", "description": "Maximum number of characters to return. Default is 8192.", }, }, "required": ["path"],14 unmodified lines
start_line_raw = params.get("start_line", 1) end_line_raw = params.get("end_line") max_chars_raw = params.get("max_chars", 20000) 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 20000.", "description": "Maximum number of characters to return. Default is 8192.", }, "max_image_paths": { "type": "integer",14 unmodified lines base_root = kwargs.get("workspace_root")
try: max_chars = int(params.get("max_chars", 20000)) 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 20000.", "description": "Maximum number of characters to return. Default is 8192.", }, }, "required": ["pattern"],280 unmodified lines read_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) 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=20000) 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 lines2728293030313233500 unmodified lines53453553653753753853954055 unmodified lines59659759859959960060160289 unmodified lines69269369469569569669769826 unmodified lines
DEFAULT_BUFFER_LIMIT = 200000DEFAULT_OUTPUT_CHARS = 20000DEFAULT_OUTPUT_CHARS = 8192DEFAULT_YIELD_MS = 200REPEAT_COLLAPSE_THRESHOLD = 3
500 unmodified lines }, "max_output_chars": { "type": "integer", "description": "Maximum number of output characters to return. Default is 20000.", "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": "Maximum number of output characters to return. Default is 20000.", "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": "Maximum number of output characters to return after the interrupt. Default is 20000.", "description": f"Maximum number of output characters to return after the interrupt. Default is {DEFAULT_OUTPUT_CHARS}.", }, }, "required": ["session_id"],10 unmodified lines1112131414151617256 unmodified lines27427527627727727827928010 unmodified linesfrom agent_base.utils import PROJECT_ROOT, env_flag, load_dotenv
DEFAULT_WEBFETCH_TIMEOUT_SECONDS = 300.0DEFAULT_WEBFETCH_MAX_CHARS = 40960DEFAULT_WEBFETCH_MAX_CHARS = 8192
def 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.", "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