CoolFace
Apppublic

Pamudu13/gemma-3-chat

sourceHugging Faceupdated 25d agoView on Hugging Face
0likes
agent_tool.py54 linesDownload Raw Back to py
1import json2from py.get_setting import HOST,PORT3from openai import AsyncOpenAI4async def get_agent_tool(settings):5    tool_agent_list = []6    for agent_id,agent_config in settings['agents'].items():7        if agent_config['enabled']:8            tool_agent_list.append({"agent_id": agent_id, "agent_skill": agent_config["system_prompt"]})9    if len(tool_agent_list) > 0:10        tool_agent_list = json.dumps(tool_agent_list, ensure_ascii=False, indent=4)11        agent_tool = {12            "type": "function",13            "function": {14                "name": "agent_tool_call",15                "description": f"根据Agent给出的agent_skill调用指定Agent工具,返回结果。当前可用的Agent工具ID以及Agent工具的agent_skill有:{tool_agent_list}",16                "parameters": {17                    "type": "object",18                    "properties": {19                        "agent_id": {20                            "type": "string",21                            "description": "需要调用的Agent工具ID",22                        },23                        "query": {24                            "type": "string",25                            "description": "需要向Agent工具发送的问题",26                        }27                    },28                    "required": ["agent_id", "query"]29                }30            }31        }32    else:33        agent_tool = None34    return agent_tool35 36async def agent_tool_call(agent_id, query):37    try:38        client = AsyncOpenAI(39            api_key="super-secret-key",40            base_url=f"http://{HOST}:{PORT}/v1"41        )42        response = await client.chat.completions.create(43            model=agent_id,44            messages=[45                {"role": "user", "content": query}46            ]47        )48        res = response.choices[0].message.content49        return str(res)50    except Exception as e:51        print(f"Error: {e}")52        return str(e)53 54