Skip to content

Commit ade34e0

Browse files
authored
♻️ Add log of llm input
♻️ Add log of llm input
2 parents 6f091d2 + 5e29615 commit ade34e0

3 files changed

Lines changed: 62 additions & 19 deletions

File tree

frontend/public/locales/en/common.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@
165165
"More accurate Q&A experience"
166166
],
167167
"page.loginPrompt.githubSupport": "⭐️ Nexent is still growing, please help me by starring on <1>GitHub</1>, thank you.",
168-
"page.loginPrompt.title": "Welcome to Nexent",
169-
"page.loginPrompt.register": "Create New Account",
170-
"page.loginPrompt.login": "Log in to account",
171-
"page.loginPrompt.intro": "Please log in to your account to access this page.",
172-
"page.loginPrompt.githubSupport": "Support us on GitHub",
173168
"page.loginPrompt.noAccount": "Don't have an account yet? Click the \"Register\" button to create your exclusive account~",
174169
"page.adminPrompt.title": "Oh, you are not an administrator",
175170
"page.adminPrompt.close": "OK",
@@ -182,9 +177,6 @@
182177
"Create and publish exclusive smart Agents",
183178
"Integrate and configure your own tools"
184179
],
185-
"page.adminPrompt.title": "Access Denied",
186-
"page.adminPrompt.intro": "You don't have permission to access this page. Please contact an administrator to request elevated privileges.",
187-
"page.adminPrompt.githubSupport": "⭐️ Nexent is still growing, please help me by starring on <1>GitHub</1>, thank you.",
188180
"page.adminPrompt.becomeAdmin": "💡 Want to become an administrator? Please visit the <1>official contact page</1> to apply for an administrator account.",
189181

190182
"chatStreamMessage.appIconAlt": "App Icon",

frontend/public/locales/zh/common.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@
165165
"更精准的问答体验"
166166
],
167167
"page.loginPrompt.githubSupport": "⭐️ Nexent还在成长中,帮帮我到<1>GitHub</1>加星支持我吧,谢谢你。",
168-
"page.loginPrompt.title": "欢迎使用 Nexent",
169-
"page.loginPrompt.register": "注册账户",
170-
"page.loginPrompt.login": "登录账户",
171-
"page.loginPrompt.intro": "请登录您的账户以访问此页面。",
172-
"page.loginPrompt.githubSupport": "在 GitHub 上支持我们",
173168
"page.loginPrompt.noAccount": "还没有账号?点击\"注册\"按钮创建您的专属账号~",
174169
"page.adminPrompt.title": "啊哦,您不是管理员",
175170
"page.adminPrompt.close": "好的",
@@ -182,9 +177,6 @@
182177
"制作和发布专属智能Agent",
183178
"集成和配置自有工具"
184179
],
185-
"page.adminPrompt.title": "暂无权限",
186-
"page.adminPrompt.intro": "您暂时没有权限访问该页面,请联系管理员为您提升权限。",
187-
"page.adminPrompt.githubSupport": "⭐️ Nexent还在成长中,帮帮我到<1>GitHub</1>加星支持我吧,谢谢你。",
188180
"page.adminPrompt.becomeAdmin": "💡 想成为管理员?请访问<1>官网联系页</1>,申请管理员账号。",
189181

190182
"chatStreamMessage.appIconAlt": "应用图标",

sdk/nexent/core/agents/core_agent.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,60 @@ def __init__(self, observer: MessageObserver, prompt_templates: Dict[str, Any] |
113113
self.observer = observer
114114
self.stop_event = threading.Event()
115115

116+
def _log_model_call_parameters(self, input_messages: List[ChatMessage], stop_sequences: List[str], additional_args: Dict[str, Any]) -> None:
117+
"""
118+
Log model call parameters with content truncation for readability.
119+
120+
121+
Args:
122+
input_messages: List of chat messages being sent to the model
123+
stop_sequences: Stop sequences for the model
124+
additional_args: Additional arguments passed to the model
125+
"""
126+
try:
127+
# Convert messages to serializable format and truncate
128+
messages_data = []
129+
for msg in input_messages:
130+
msg_dict = msg.model_dump() if hasattr(msg, 'model_dump') else (
131+
msg.__dict__ if hasattr(msg, '__dict__') else str(msg)
132+
)
133+
messages_data.append(msg_dict)
134+
135+
# Format as JSON with truncation for readability
136+
messages_json = json.dumps(messages_data, indent=2, ensure_ascii=False, default=str)
137+
truncated_messages = truncate_content(messages_json, max_length=1000)
138+
139+
# Format stop sequences
140+
stop_seq_str = ", ".join(f'"{seq}"' for seq in stop_sequences) if stop_sequences else "None"
141+
142+
# Format additional args (excluding sensitive data)
143+
safe_args = {}
144+
for key, value in additional_args.items():
145+
if key.lower() in ['api_key', 'token', 'password', 'secret']:
146+
safe_args[key] = "***REDACTED***"
147+
else:
148+
safe_args[key] = value
149+
150+
args_str = json.dumps(safe_args, indent=2, ensure_ascii=False) if safe_args else "None"
151+
152+
# Create log content
153+
log_content = f"""Input Messages ({len(input_messages)} total):
154+
{truncated_messages}
155+
156+
Stop Sequences: [{stop_seq_str}]
157+
Additional Args:
158+
{args_str}"""
159+
160+
self.logger.log_markdown(
161+
content=log_content,
162+
title="MODEL INPUT PARAMETERS",
163+
level=LogLevel.INFO
164+
)
165+
166+
except Exception as e:
167+
# Don't let logging errors break the model call
168+
self.logger.log(f"Failed to log model call parameters: {e}", level=LogLevel.WARNING)
169+
116170
def _step_stream(self, memory_step: ActionStep) -> Generator[Any]:
117171
"""
118172
Perform one step in the ReAct framework: the agent thinks, acts, and observes the result.
@@ -129,10 +183,15 @@ def _step_stream(self, memory_step: ActionStep) -> Generator[Any]:
129183
memory_step.model_input_messages = input_messages
130184
stop_sequences = ["<END_CODE>", "Observation:", "Calling tools:", "<END_CODE"]
131185

186+
# Prepare additional arguments
187+
additional_args: dict[str, Any] = {}
188+
if self._use_structured_outputs_internally:
189+
additional_args["response_format"] = CODEAGENT_RESPONSE_FORMAT
190+
191+
# Log model call parameters before execution
192+
self._log_model_call_parameters(input_messages, stop_sequences, additional_args)
193+
132194
try:
133-
additional_args: dict[str, Any] = {}
134-
if self._use_structured_outputs_internally:
135-
additional_args["response_format"] = CODEAGENT_RESPONSE_FORMAT
136195
chat_message: ChatMessage = self.model(input_messages,
137196
stop_sequences=stop_sequences, **additional_args)
138197
memory_step.model_output_message = chat_message

0 commit comments

Comments
 (0)