# Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. def create_agent(self, agent_name: str, system_prompt: str, provider_title: str, model_id: str, output_type: ResponseModel, deps_type: DepsModel) -> Agent: """ create_agent方法,将保存的适配器转化为agent对象并返回 Args: agent_name: agent名字,代表实例化个体起的名字 system_prompt: 系统提示词,给llm的系统提示词 provider_title: 供应商名称 model_id: 模型Id,实例化agent所输入的model_id output_type: 输出格式,实例化agent后,对应llm所应当输出的格式 deps_type: 依赖格式,输入llm的格式 Returns: 一个pydanticAI的Agent对象,包含对应的apikey,url,model_id等信息,应当挂载到individual类的agent属性下 Raises: ProviderNotExistError 当在provider_register属性里找不到供应商的自定义名称时抛出 ModelNotExistError 在获取的provider的模型列表中找不到输入的model_id抛出 """ if provider_title not in self.provider_register: raise ProviderNotExistError("提供商不存在") provider = self.provider_register[provider_title] if model_id not in provider.provider_models: raise ModelNotExistError("模型不存在") model = self._agent_factory.create_model(provider.provider_type, provider.provider_apikey, provider.provider_url, model_id) agent = Agent(model=model, name=agent_name, system_prompt=system_prompt, output_type=output_type, deps_type=deps_type) return agent