Skip to content

Commit 4488072

Browse files
committed
add
add
1 parent 2ee079d commit 4488072

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
- [ ] web search tool
5555
- [ ] RAG 知识库
5656
- [ ] A2A hand off: 代码手多次反思错误,hand off 更聪明模型 agent
57+
- [ ] chat / agent mode
5758

5859
## 视频demo
5960

backend/.env.dev.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ENV=dev
2-
# support all model, check out https://docs.litellm.ai/docs/
2+
# support all model, check out https://docs.litellm.ai/docs/providers
33
# e.g. gpt-4.1,deepseek/deepseek-chat
4+
# docs/md/tutorial
45
# 为每个 agent 配置合适的模型
56
COORDINATOR_API_KEY=
67
COORDINATOR_MODEL=

backend/app/core/llm/llm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from litellm import acompletion
1414
import litellm
1515
from app.schemas.enums import AgentType
16+
from app.utils.track import agent_metrics
17+
18+
litellm.callbacks = [agent_metrics]
1619

1720

1821
class LLM:
@@ -49,6 +52,7 @@ async def chat(
4952
"messages": history,
5053
"stream": False,
5154
"top_p": top_p,
55+
"metadata": {"agent_name": agent_name},
5256
}
5357

5458
if tools:

backend/app/utils/track.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1+
from litellm.integrations.custom_logger import CustomLogger
12
import litellm
2-
from app.services.redis_manager import redis_manager
33

44

5-
# track_cost_callback
6-
def track_cost_callback(
7-
kwargs, # kwargs to completion
8-
completion_response, # response from completion
9-
start_time,
10-
end_time, # start/end time
11-
):
12-
try:
13-
response_cost = kwargs.get("response_cost", 0)
14-
total_tokens = kwargs.get("total_tokens", 0)
5+
class AgentMetrics(CustomLogger):
6+
#### ASYNC ####
157

16-
# redis
17-
print("streaming response_cost", response_cost)
18-
print("streaming total_tokens", total_tokens)
8+
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
9+
try:
10+
# response_cost = kwargs.get("response_cost", 0)
11+
# print("streaming response_cost", response_cost)
12+
print("agent_name", kwargs["litellm_params"]["metadata"]["agent_name"])
13+
except:
14+
pass
1915

20-
# 更新redis
21-
return
22-
except Exception as e:
23-
print(e)
24-
pass
16+
async def async_log_failure_event(self, kwargs, response_obj, start_time, end_time):
17+
print(f"On Async Failure")
2518

2619

27-
# set callback
28-
litellm.success_callback = [track_cost_callback] # set custom callback function
20+
# 全局指标收集器实例
21+
agent_metrics = AgentMetrics()

0 commit comments

Comments
 (0)