Skip to content

Commit 5b999ed

Browse files
Jacksunweicopybara-github
authored andcommitted
chore: Uses pydantic Field for Agent configs, so that the generated AgentConfig.json json schema can carry field description
PiperOrigin-RevId: 797094012
1 parent bb8ebd1 commit 5b999ed

File tree

7 files changed

+219
-122
lines changed

7 files changed

+219
-122
lines changed

src/google/adk/agents/base_agent_config.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from pydantic import BaseModel
2626
from pydantic import ConfigDict
27+
from pydantic import Field
2728

2829
from ..utils.feature_decorator import experimental
2930
from .common_configs import AgentRefConfig
@@ -43,32 +44,41 @@ class BaseAgentConfig(BaseModel):
4344
extra='allow',
4445
)
4546

46-
agent_class: Union[Literal['BaseAgent'], str] = 'BaseAgent'
47-
"""Required. The class of the agent. The value is used to differentiate
48-
among different agent classes."""
47+
agent_class: Union[Literal['BaseAgent'], str] = Field(
48+
default='BaseAgent',
49+
description=(
50+
'Required. The class of the agent. The value is used to differentiate'
51+
' among different agent classes.'
52+
),
53+
)
4954

50-
name: str
51-
"""Required. The name of the agent."""
55+
name: str = Field(description='Required. The name of the agent.')
5256

53-
description: str = ''
54-
"""Optional. The description of the agent."""
57+
description: str = Field(
58+
default='', description='Optional. The description of the agent.'
59+
)
5560

56-
sub_agents: Optional[List[AgentRefConfig]] = None
57-
"""Optional. The sub-agents of the agent."""
61+
sub_agents: Optional[List[AgentRefConfig]] = Field(
62+
default=None, description='Optional. The sub-agents of the agent.'
63+
)
5864

59-
before_agent_callbacks: Optional[List[CodeConfig]] = None
60-
"""Optional. The before_agent_callbacks of the agent.
65+
before_agent_callbacks: Optional[List[CodeConfig]] = Field(
66+
default=None,
67+
description="""\
68+
Optional. The before_agent_callbacks of the agent.
6169
62-
Example:
70+
Example:
6371
64-
```
65-
before_agent_callbacks:
66-
- name: my_library.security_callbacks.before_agent_callback
67-
```
68-
"""
72+
```
73+
before_agent_callbacks:
74+
- name: my_library.security_callbacks.before_agent_callback
75+
```""",
76+
)
6977

70-
after_agent_callbacks: Optional[List[CodeConfig]] = None
71-
"""Optional. The after_agent_callbacks of the agent."""
78+
after_agent_callbacks: Optional[List[CodeConfig]] = Field(
79+
default=None,
80+
description='Optional. The after_agent_callbacks of the agent.',
81+
)
7282

7383
def to_agent_config(
7484
self, custom_agent_config_cls: Type[TBaseAgentConfig]

0 commit comments

Comments
 (0)