Skip to content

Commit d1874a4

Browse files
committed
refactor(tools): Convert LangExtractToolConfig to dataclass
Use @DataClass from the standard library instead of a manual __init__, reducing boilerplate and making the config class more concise and idiomatic Python.
1 parent 69b9fd0 commit d1874a4

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/google/adk_community/tools/langextract_tool.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from __future__ import annotations
1616

1717
import asyncio
18+
from dataclasses import dataclass
19+
from dataclasses import field
1820
import logging
1921
from typing import Any
2022
from typing import Optional
@@ -178,31 +180,20 @@ async def run_async(
178180
return {'error': f'Extraction failed: {e}'}
179181

180182

183+
@dataclass
181184
class LangExtractToolConfig:
182-
"""Configuration dataclass for LangExtractTool."""
183-
184-
def __init__(
185-
self,
186-
*,
187-
name: str = 'langextract',
188-
description: str = (
189-
'Extracts structured information from unstructured text.'
190-
),
191-
examples: Optional[list[lx.data.ExampleData]] = None,
192-
model_id: str = 'gemini-2.5-flash',
193-
api_key: Optional[str] = None,
194-
extraction_passes: int = 1,
195-
max_workers: int = 1,
196-
max_char_buffer: int = 4000,
197-
):
198-
self.name = name
199-
self.description = description
200-
self.examples = examples or []
201-
self.model_id = model_id
202-
self.api_key = api_key
203-
self.extraction_passes = extraction_passes
204-
self.max_workers = max_workers
205-
self.max_char_buffer = max_char_buffer
185+
"""Configuration for LangExtractTool."""
186+
187+
name: str = 'langextract'
188+
description: str = (
189+
'Extracts structured information from unstructured text.'
190+
)
191+
examples: list[lx.data.ExampleData] = field(default_factory=list)
192+
model_id: str = 'gemini-2.5-flash'
193+
api_key: Optional[str] = None
194+
extraction_passes: int = 1
195+
max_workers: int = 1
196+
max_char_buffer: int = 4000
206197

207198
def build(self) -> LangExtractTool:
208199
"""Instantiate a LangExtractTool from this config."""

0 commit comments

Comments
 (0)