A tool that wraps an agent. This tool allows an agent to be called as a tool within a larger application. The agent's input schema is used to define the tool's input parameters, and the agent's output is returned as the tool's result. Attributes: agent: The agent to wrap. skip_summ
| 105 | |
| 106 | |
| 107 | class AgentTool(BaseTool): |
| 108 | """A tool that wraps an agent. |
| 109 | |
| 110 | This tool allows an agent to be called as a tool within a larger application. |
| 111 | The agent's input schema is used to define the tool's input parameters, and |
| 112 | the agent's output is returned as the tool's result. |
| 113 | |
| 114 | Attributes: |
| 115 | agent: The agent to wrap. |
| 116 | skip_summarization: Whether to skip summarization of the agent output. |
| 117 | include_plugins: Whether to propagate plugins from the parent runner context |
| 118 | to the agent's runner. When True (default), the agent will inherit all |
| 119 | plugins from its parent. Set to False to run the agent with an isolated |
| 120 | plugin environment. |
| 121 | """ |
| 122 | |
| 123 | def __init__( |
| 124 | self, |
| 125 | agent: BaseAgent, |
| 126 | skip_summarization: bool = False, |
| 127 | *, |
| 128 | include_plugins: bool = True, |
| 129 | propagate_grounding_metadata: bool = False, |
| 130 | ): |
| 131 | self.agent = agent |
| 132 | self.skip_summarization: bool = skip_summarization |
| 133 | self.include_plugins = include_plugins |
| 134 | self.propagate_grounding_metadata = propagate_grounding_metadata |
| 135 | |
| 136 | super().__init__(name=agent.name, description=agent.description) |
| 137 | |
| 138 | @model_validator(mode='before') |
| 139 | @classmethod |
| 140 | def populate_name(cls, data: Any) -> Any: |
| 141 | data['name'] = data['agent'].name |
| 142 | return data |
| 143 | |
| 144 | @override |
| 145 | def _get_declaration(self) -> types.FunctionDeclaration: |
| 146 | from ..utils.variant_utils import GoogleLLMVariant |
| 147 | |
| 148 | input_schema = _get_input_schema(self.agent) |
| 149 | output_schema = _get_output_schema(self.agent) |
| 150 | |
| 151 | if input_schema: |
| 152 | result = _automatic_function_calling_util.build_function_declaration( |
| 153 | func=input_schema, variant=self._api_variant |
| 154 | ) |
| 155 | # Override the description with the agent's description |
| 156 | result.description = self.agent.description |
| 157 | else: |
| 158 | if is_feature_enabled(FeatureName.JSON_SCHEMA_FOR_FUNC_DECL): |
| 159 | result = types.FunctionDeclaration( |
| 160 | name=self.name, |
| 161 | description=self.agent.description, |
| 162 | parameters_json_schema={ |
| 163 | 'type': 'object', |
| 164 | 'properties': { |
no outgoing calls