mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
core/agent+config: soft context budget in estimated tokens
Replace max_context_chars with max_context_tokens (default 200k est. tokens via char/4); compact and /status use the token budget.
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from plyngent.lmproto.openai_compatible.model import SystemChatMessage, UserChatMessage
|
||||
|
||||
from .budget import DEFAULT_CONTEXT_MAX_CHARS, DEFAULT_TOOL_RESULT_MAX_CHARS
|
||||
from .budget import DEFAULT_CONTEXT_MAX_TOKENS, DEFAULT_TOOL_RESULT_MAX_CHARS
|
||||
from .events import UsageEvent
|
||||
from .loop import DEFAULT_MAX_ROUNDS, run_chat_loop
|
||||
from .usage import TokenUsage
|
||||
@@ -37,7 +37,7 @@ class ChatAgent:
|
||||
system_prompt: str | None
|
||||
max_tool_result_chars: int
|
||||
parallel_tools: bool
|
||||
max_context_chars: int
|
||||
max_context_tokens: int
|
||||
messages: list[AnyChatMessage]
|
||||
pending_retry_text: str | None
|
||||
session_usage: TokenUsage
|
||||
@@ -59,7 +59,7 @@ class ChatAgent:
|
||||
system_prompt: str | None = None,
|
||||
max_tool_result_chars: int = DEFAULT_TOOL_RESULT_MAX_CHARS,
|
||||
parallel_tools: bool = True,
|
||||
max_context_chars: int = DEFAULT_CONTEXT_MAX_CHARS,
|
||||
max_context_tokens: int = DEFAULT_CONTEXT_MAX_TOKENS,
|
||||
) -> None:
|
||||
self.client = client
|
||||
self.model = model
|
||||
@@ -73,7 +73,7 @@ class ChatAgent:
|
||||
self.system_prompt = system_prompt
|
||||
self.max_tool_result_chars = max_tool_result_chars
|
||||
self.parallel_tools = parallel_tools
|
||||
self.max_context_chars = max_context_chars
|
||||
self.max_context_tokens = max_context_tokens
|
||||
self.messages = list(messages) if messages is not None else []
|
||||
self.pending_retry_text = None
|
||||
self.session_usage = TokenUsage()
|
||||
@@ -135,7 +135,7 @@ class ChatAgent:
|
||||
stream=self.stream,
|
||||
max_tool_result_chars=self.max_tool_result_chars,
|
||||
parallel_tools=self.parallel_tools,
|
||||
max_context_chars=self.max_context_chars,
|
||||
max_context_tokens=self.max_context_tokens,
|
||||
):
|
||||
if isinstance(event, UsageEvent):
|
||||
turn_usage = turn_usage.add(event.usage)
|
||||
|
||||
Reference in New Issue
Block a user