Skip to content

Commit 962eae5

Browse files
committed
fix: update callback function to accurately use LlmResponse and adjust Part order insertion
1 parent 1c283b7 commit 962eae5

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

agents/matmaster_agent/callback.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import litellm
88
from google.adk.agents.callback_context import CallbackContext
9-
from google.adk.models import LlmResponse, LlmRequest
9+
from google.adk.models import LlmResponse
1010
from google.genai import types
1111
from google.genai.types import FunctionCall, Part, FunctionResponse
1212

@@ -53,7 +53,8 @@ async def matmaster_set_lang(callback_context: CallbackContext) -> Optional[type
5353
callback_context.state['target_language'] = language
5454

5555

56-
async def matmaster_check_job_status(callback_context: CallbackContext, llm_response: LlmRequest) -> Optional[
56+
# after_model_callback
57+
async def matmaster_check_job_status(callback_context: CallbackContext, llm_response: LlmResponse) -> Optional[
5758
LlmResponse]:
5859
if (
5960
(jobs_dict := callback_context.state['long_running_jobs']) and
@@ -76,15 +77,15 @@ async def matmaster_check_job_status(callback_context: CallbackContext, llm_resp
7677
llm_response.content.parts.insert(0, Part(text=job_complete_intro.format(job_id=job_id),
7778
function_call=FunctionCall(id=function_call_id,
7879
name='transfer_to_agent',
79-
args={'agent_name': agent_name}),
80-
function_response=FunctionResponse(id=function_call_id,
81-
name='transfer_to_agent',
82-
response=None)
80+
args={'agent_name': agent_name})
8381
)
8482
)
83+
llm_response.content.parts.insert(1, Part(function_response=FunctionResponse(id=function_call_id,
84+
name='transfer_to_agent',
85+
response=None)))
86+
return llm_response
8587

8688

87-
# after_model_callback
8889
async def matmaster_check_transfer(callback_context: CallbackContext, llm_response: LlmResponse) -> Optional[
8990
LlmResponse]:
9091
# 检查响应是否有效

agents/matmaster_agent/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from agents.matmaster_agent.logger import logger
1313
import litellm
1414

15+
1516
# litellm._turn_on_debug()
1617

1718

@@ -67,7 +68,8 @@ async def agent_main() -> None:
6768
# user_input = "帮我用DPA优化这个结构:https://dp-storage-test2.oss-cn-zhangjiakou.aliyuncs.com/bohrium-test/110663/12791/store/7ba41529-5af4-4e38-a6fb-c569cd769dd9/outputs/structure_paths/structure_bulk.cif"
6869
# user_input = "帮我检索TiO2"
6970
# user_input = "请你为我搭建一个氯化钠的结构"
70-
user_input = '用openlam查找一个TiO2'
71+
user_input = "我想要一个bandgap 小于0.5ev的结构,空间群225,生成数量1"
72+
# user_input = '用openlam查找一个TiO2'
7173
print(f"🧑 用户:{user_input}")
7274

7375
# Create the initial content with user input

0 commit comments

Comments
 (0)