Agent configuration for registration, similar to `ToolConfig`.
| 61 | error: Optional[ACPError] = None |
| 62 | |
| 63 | class AgentConfig(BaseModel): |
| 64 | """Agent configuration for registration, similar to `ToolConfig`.""" |
| 65 | model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow") |
| 66 | |
| 67 | name: str = Field(description="The name of the agent") |
| 68 | description: str = Field(description="The description of the agent") |
| 69 | version: str = Field(default="1.0.0", description="Version of the agent") |
| 70 | metadata: Optional[Dict[str, Any]] = Field(default_factory=dict) |
| 71 | require_grad: bool = Field(default=False, description="Whether the agent requires gradients") |
| 72 | |
| 73 | cls: Optional[Any] = None |
| 74 | config: Optional[Dict[str, Any]] = Field(default_factory=dict,description="The initialization configuration of the agent",) |
| 75 | instance: Optional[Any] = None |
| 76 | |
| 77 | code: Optional[str] = Field(default=None, description="Source code for dynamically generated agent classes (used when cls cannot be imported from a module)") |
| 78 | |
| 79 | function_calling: Optional[Dict[str, Any]] = Field( |
| 80 | default=None, description="Default function calling representation" |
| 81 | ) |
| 82 | text: Optional[str] = Field( |
| 83 | default=None, description="Default text representation of the agent" |
| 84 | ) |
| 85 | args_schema: Optional[Type[BaseModel]] = Field( |
| 86 | default=None, description="Default args schema (BaseModel type)" |
| 87 | ) |
| 88 | |
| 89 | def model_dump(self, **kwargs) -> Dict[str, Any]: |
| 90 | """Dump the model to a dictionary, recursively serializing nested Pydantic models.""" |
| 91 | |
| 92 | result = { |
| 93 | "name": self.name, |
| 94 | "description": self.description, |
| 95 | "metadata": self.metadata, |
| 96 | "version": self.version, |
| 97 | "require_grad": self.require_grad, |
| 98 | |
| 99 | "cls": dynamic_manager.get_class_string(self.cls) if self.cls else None, |
| 100 | "config": self.config, |
| 101 | "instance": None, |
| 102 | "code": self.code, |
| 103 | |
| 104 | "function_calling": self.function_calling, |
| 105 | "text": self.text, |
| 106 | "args_schema": dynamic_manager.serialize_args_schema(self.args_schema) if self.args_schema else None, |
| 107 | } |
| 108 | |
| 109 | return result |
| 110 | |
| 111 | @classmethod |
| 112 | def model_validate(cls, data: Dict[str, Any]) -> 'AgentConfig': |
| 113 | """Validate the model from a dictionary.""" |
| 114 | name = data.get("name") |
| 115 | description = data.get("description") |
| 116 | metadata = data.get("metadata", {}) |
| 117 | version = data.get("version") |
| 118 | require_grad = data.get("require_grad", False) |
| 119 | |
| 120 | cls_ = None |
no outgoing calls
no test coverage detected