|
24 | 24 | from ..examples.base_example_provider import BaseExampleProvider
|
25 | 25 | from ..examples.example import Example
|
26 | 26 | from .base_tool import BaseTool
|
| 27 | +from .base_tool import BaseToolConfig |
| 28 | +from .base_tool import ToolArgsConfig |
27 | 29 | from .tool_context import ToolContext
|
28 | 30 |
|
29 | 31 | if TYPE_CHECKING:
|
@@ -60,3 +62,34 @@ async def process_llm_request(
|
60 | 62 | self.examples, parts[0].text, llm_request.model
|
61 | 63 | )
|
62 | 64 | ])
|
| 65 | + |
| 66 | + @override |
| 67 | + @classmethod |
| 68 | + def from_config( |
| 69 | + cls: type[ExampleTool], config: ToolArgsConfig, config_abs_path: str |
| 70 | + ) -> ExampleTool: |
| 71 | + from ..agents import config_agent_utils |
| 72 | + |
| 73 | + example_tool_config = ExampleToolConfig.model_validate(config.model_dump()) |
| 74 | + if isinstance(example_tool_config.examples, str): |
| 75 | + example_provider = config_agent_utils.resolve_fully_qualified_name( |
| 76 | + example_tool_config.examples |
| 77 | + ) |
| 78 | + if not isinstance(example_provider, BaseExampleProvider): |
| 79 | + raise ValueError( |
| 80 | + 'Example provider must be an instance of BaseExampleProvider.' |
| 81 | + ) |
| 82 | + return cls(example_provider) |
| 83 | + elif isinstance(example_tool_config.examples, list): |
| 84 | + return cls(example_tool_config.examples) |
| 85 | + else: |
| 86 | + raise ValueError( |
| 87 | + 'Example tool config must be a list of examples or a fully-qualified' |
| 88 | + ' name to a BaseExampleProvider object in code.' |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +class ExampleToolConfig(BaseToolConfig): |
| 93 | + examples: Union[list[Example], str] |
| 94 | + """The examples to add to the LLM request. User can either provide a list of |
| 95 | + examples or a fully-qualified name to a BaseExampleProvider object in code.""" |
0 commit comments