Skip to content

Commit ef7c34e

Browse files
feat: 跟踪使用情况
1 parent f2d6410 commit ef7c34e

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
'''
22
Author: ai-business-hql [email protected]
33
Date: 2025-02-17 20:53:45
4-
LastEditors: ai-business-hql qingli.hql@alibaba-inc.com
5-
LastEditTime: 2025-06-24 17:09:23
4+
LastEditors: ai-business-hql ai.bussiness.hql@gmail.com
5+
LastEditTime: 2025-11-20 20:03:20
66
FilePath: /comfyui_copilot/__init__.py
77
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
'''
99
# Copyright (C) 2025 AIDC-AI
1010
# Licensed under the MIT License.
1111

1212
import sys
13-
import os
13+
import asyncio
14+
1415

1516
# Ensure 'agents' resolves to openai-agents (not legacy RL package)
1617
try:

backend/agent_factory.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Author: ai-business-hql [email protected]
33
Date: 2025-07-31 19:38:08
44
LastEditors: ai-business-hql [email protected]
5-
LastEditTime: 2025-09-03 11:00:57
5+
LastEditTime: 2025-11-20 17:51:33
66
FilePath: /comfyui_copilot/backend/agent_factory.py
77
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
'''
9-
import os
9+
1010
try:
11-
from agents import Agent, OpenAIChatCompletionsModel, ModelSettings
11+
from agents import Agent, OpenAIChatCompletionsModel, ModelSettings, Runner, set_trace_processors, set_tracing_disabled, set_default_openai_api
1212
if not hasattr(__import__('agents'), 'Agent'):
1313
raise ImportError
1414
except Exception:
@@ -28,6 +28,7 @@
2828

2929
from agents._config import set_default_openai_api
3030
from agents.tracing import set_tracing_disabled
31+
import asyncio
3132
# from .utils.logger import log
3233

3334
# def load_env_config():
@@ -46,7 +47,9 @@
4647
# load_env_config()
4748

4849
set_default_openai_api("chat_completions")
49-
set_tracing_disabled(True)
50+
set_tracing_disabled(False)
51+
52+
5053
def create_agent(**kwargs) -> Agent:
5154
# 通过用户配置拿/环境变量
5255
config = kwargs.pop("config") if "config" in kwargs else {}
@@ -59,13 +62,13 @@ def create_agent(**kwargs) -> Agent:
5962
# Determine base URL and API key
6063
base_url = LLM_DEFAULT_BASE_URL
6164
api_key = get_comfyui_copilot_api_key() or ""
62-
65+
6366
if config:
6467
if config.get("openai_base_url") and config.get("openai_base_url") != "":
6568
base_url = config.get("openai_base_url")
6669
if config.get("openai_api_key") and config.get("openai_api_key") != "":
6770
api_key = config.get("openai_api_key")
68-
71+
6972
# Check if this is LMStudio and adjust API key handling
7073
is_lmstudio = is_lmstudio_url(base_url)
7174
if is_lmstudio and not api_key:

backend/service/mcp_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: ai-business-hql [email protected]
33
Date: 2025-06-16 16:50:17
44
LastEditors: ai-business-hql [email protected]
5-
LastEditTime: 2025-11-19 20:16:03
5+
LastEditTime: 2025-11-20 17:44:52
66
FilePath: /comfyui_copilot/backend/service/mcp-client.py
77
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
'''
@@ -222,6 +222,13 @@ async def on_handoff(ctx: RunContextWrapper[None], input_data: HandoffRewriteDat
222222
agent_input = messages
223223
log.info(f"-- Processing {len(messages)} messages")
224224

225+
from agents import Agent, Runner, set_trace_processors, set_tracing_disabled, set_default_openai_api
226+
from langsmith.wrappers import OpenAIAgentsTracingProcessor
227+
228+
set_tracing_disabled(False)
229+
set_default_openai_api("chat_completions")
230+
set_trace_processors([OpenAIAgentsTracingProcessor()])
231+
225232
result = Runner.run_streamed(
226233
agent,
227234
input=agent_input,

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ httpx>=0.24.0
1111
pytest>=6.0.0
1212
pytest-asyncio>=0.18.0
1313
openai-agents>=0.3.0
14+
langsmith>=0.4.0
1415
fastmcp
1516

1617
modelscope>=1.28.0
17-
urllib3>=1.26,<2.0
18+
urllib3>=1.26,<2.0

0 commit comments

Comments
 (0)