Skip to content

Commit dea1ee1

Browse files
seanzhougooglecopybara-github
authored andcommitted
docs: Fix docstring and update module public name list for generating API references
To fix google/adk-docs#131 PiperOrigin-RevId: 783080206
1 parent 62a6119 commit dea1ee1

File tree

15 files changed

+170
-173
lines changed

15 files changed

+170
-173
lines changed

src/google/adk/agents/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from .base_agent import BaseAgent
16+
from .invocation_context import InvocationContext
1617
from .live_request_queue import LiveRequest
1718
from .live_request_queue import LiveRequestQueue
1819
from .llm_agent import Agent
@@ -29,4 +30,8 @@
2930
'LoopAgent',
3031
'ParallelAgent',
3132
'SequentialAgent',
33+
'InvocationContext',
34+
'LiveRequest',
35+
'LiveRequestQueue',
36+
'RunConfig',
3237
]

src/google/adk/agents/invocation_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class InvocationContext(BaseModel):
149149
"""The running streaming tools of this invocation."""
150150

151151
transcription_cache: Optional[list[TranscriptionEntry]] = None
152-
"""Caches necessary, data audio or contents, that are needed by transcription."""
152+
"""Caches necessary data, audio or contents, that are needed by transcription."""
153153

154154
run_config: Optional[RunConfig] = None
155155
"""Configurations for live agents under this invocation."""

src/google/adk/agents/llm_agent.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ class LlmAgent(BaseAgent):
168168
"""Controls content inclusion in model requests.
169169
170170
Options:
171-
default: Model receives relevant conversation history
172-
none: Model receives no prior history, operates solely on current
173-
instruction and input
171+
default: Model receives relevant conversation history
172+
none: Model receives no prior history, operates solely on current
173+
instruction and input
174174
"""
175175

176176
# Controlled input/output configurations - Start
@@ -179,8 +179,9 @@ class LlmAgent(BaseAgent):
179179
output_schema: Optional[type[BaseModel]] = None
180180
"""The output schema when agent replies.
181181
182-
NOTE: when this is set, agent can ONLY reply and CANNOT use any tools, such as
183-
function tools, RAGs, agent transfer, etc.
182+
NOTE:
183+
When this is set, agent can ONLY reply and CANNOT use any tools, such as
184+
function tools, RAGs, agent transfer, etc.
184185
"""
185186
output_key: Optional[str] = None
186187
"""The key in session state to store the output of the agent.
@@ -195,9 +196,9 @@ class LlmAgent(BaseAgent):
195196
planner: Optional[BasePlanner] = None
196197
"""Instructs the agent to make a plan and execute it step by step.
197198
198-
NOTE: to use model's built-in thinking features, set the `thinking_config`
199-
field in `google.adk.planners.built_in_planner`.
200-
199+
NOTE:
200+
To use model's built-in thinking features, set the `thinking_config`
201+
field in `google.adk.planners.built_in_planner`.
201202
"""
202203

203204
code_executor: Optional[BaseCodeExecutor] = None
@@ -206,7 +207,8 @@ class LlmAgent(BaseAgent):
206207
207208
Check out available code executions in `google.adk.code_executor` package.
208209
209-
NOTE: to use model's built-in code executor, use the `BuiltInCodeExecutor`.
210+
NOTE:
211+
To use model's built-in code executor, use the `BuiltInCodeExecutor`.
210212
"""
211213
# Advance features - End
212214

src/google/adk/code_executors/base_code_executor.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import abc
1618
from typing import List
1719

@@ -42,42 +44,35 @@ class BaseCodeExecutor(BaseModel):
4244
"""
4345

4446
optimize_data_file: bool = False
45-
"""
46-
If true, extract and process data files from the model request
47+
"""If true, extract and process data files from the model request
4748
and attach them to the code executor.
48-
Supported data file MimeTypes are [text/csv].
4949
50+
Supported data file MimeTypes are [text/csv].
5051
Default to False.
5152
"""
5253

5354
stateful: bool = False
54-
"""
55-
Whether the code executor is stateful. Default to False.
56-
"""
55+
"""Whether the code executor is stateful. Default to False."""
5756

5857
error_retry_attempts: int = 2
59-
"""
60-
The number of attempts to retry on consecutive code execution errors. Default to 2.
61-
"""
58+
"""The number of attempts to retry on consecutive code execution errors. Default to 2."""
6259

6360
code_block_delimiters: List[tuple[str, str]] = [
6461
('```tool_code\n', '\n```'),
6562
('```python\n', '\n```'),
6663
]
67-
"""
68-
The list of the enclosing delimiters to identify the code blocks.
69-
For example, the delimiter ('```python\n', '\n```') can be
70-
used to identify code blocks with the following format:
64+
"""The list of the enclosing delimiters to identify the code blocks.
7165
72-
```python
73-
print("hello")
74-
```
66+
For example, the delimiter ('```python\\n', '\\n```') can be
67+
used to identify code blocks with the following format::
68+
69+
```python
70+
print("hello")
71+
```
7572
"""
7673

7774
execution_result_delimiters: tuple[str, str] = ('```tool_output\n', '\n```')
78-
"""
79-
The delimiters to format the code execution result.
80-
"""
75+
"""The delimiters to format the code execution result."""
8176

8277
@abc.abstractmethod
8378
def execute_code(

src/google/adk/runners.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ def run(
122122
) -> Generator[Event, None, None]:
123123
"""Runs the agent.
124124
125-
NOTE: This sync interface is only for local testing and convenience purpose.
126-
Consider using `run_async` for production usage.
125+
NOTE:
126+
This sync interface is only for local testing and convenience purpose.
127+
Consider using `run_async` for production usage.
127128
128129
Args:
129130
user_id: The user ID of the session.
@@ -350,7 +351,7 @@ async def run_live(
350351
This feature is **experimental** and its API or behavior may change
351352
in future releases.
352353
353-
.. note::
354+
.. NOTE::
354355
Either `session` or both `user_id` and `session_id` must be provided.
355356
"""
356357
if session is None and (user_id is None or session_id is None):
@@ -433,9 +434,10 @@ def _find_agent_to_run(
433434
"""Finds the agent to run to continue the session.
434435
435436
A qualified agent must be either of:
437+
436438
- The agent that returned a function call and the last user message is a
437439
function response to this function call.
438-
- The root agent;
440+
- The root agent.
439441
- An LlmAgent who replied last and is capable to transfer to any other agent
440442
in the agent hierarchy.
441443

src/google/adk/tools/apihub_tool/apihub_toolset.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,25 @@
3535
class APIHubToolset(BaseToolset):
3636
"""APIHubTool generates tools from a given API Hub resource.
3737
38-
Examples:
38+
Examples::
3939
40-
```
41-
apihub_toolset = APIHubToolset(
42-
apihub_resource_name="projects/test-project/locations/us-central1/apis/test-api",
43-
service_account_json="...",
44-
tool_filter=lambda tool, ctx=None: tool.name in ('my_tool',
45-
'my_other_tool')
46-
)
47-
48-
# Get all available tools
49-
agent = LlmAgent(tools=apihub_toolset)
40+
apihub_toolset = APIHubToolset(
41+
apihub_resource_name="projects/test-project/locations/us-central1/apis/test-api",
42+
service_account_json="...",
43+
tool_filter=lambda tool, ctx=None: tool.name in ('my_tool',
44+
'my_other_tool')
45+
)
5046
51-
```
47+
# Get all available tools
48+
agent = LlmAgent(tools=apihub_toolset)
5249
5350
**apihub_resource_name** is the resource name from API Hub. It must include
54-
API name, and can optionally include API version and spec name.
55-
- If apihub_resource_name includes a spec resource name, the content of that
56-
spec will be used for generating the tools.
57-
- If apihub_resource_name includes only an api or a version name, the
58-
first spec of the first version of that API will be used.
51+
API name, and can optionally include API version and spec name.
52+
53+
- If apihub_resource_name includes a spec resource name, the content of that
54+
spec will be used for generating the tools.
55+
- If apihub_resource_name includes only an api or a version name, the
56+
first spec of the first version of that API will be used.
5957
"""
6058

6159
def __init__(
@@ -78,44 +76,45 @@ def __init__(
7876
):
7977
"""Initializes the APIHubTool with the given parameters.
8078
81-
Examples:
82-
```
83-
apihub_toolset = APIHubToolset(
84-
apihub_resource_name="projects/test-project/locations/us-central1/apis/test-api",
85-
service_account_json="...",
86-
)
79+
Examples::
8780
88-
# Get all available tools
89-
agent = LlmAgent(tools=[apihub_toolset])
81+
apihub_toolset = APIHubToolset(
82+
apihub_resource_name="projects/test-project/locations/us-central1/apis/test-api",
83+
service_account_json="...",
84+
)
9085
91-
apihub_toolset = APIHubToolset(
92-
apihub_resource_name="projects/test-project/locations/us-central1/apis/test-api",
93-
service_account_json="...",
94-
tool_filter = ['my_tool']
95-
)
96-
# Get a specific tool
97-
agent = LlmAgent(tools=[
98-
...,
99-
apihub_toolset,
100-
])
101-
```
86+
# Get all available tools
87+
agent = LlmAgent(tools=[apihub_toolset])
88+
89+
apihub_toolset = APIHubToolset(
90+
apihub_resource_name="projects/test-project/locations/us-central1/apis/test-api",
91+
service_account_json="...",
92+
tool_filter = ['my_tool']
93+
)
94+
# Get a specific tool
95+
agent = LlmAgent(tools=[
96+
...,
97+
apihub_toolset,
98+
])
10299
103100
**apihub_resource_name** is the resource name from API Hub. It must include
104101
API name, and can optionally include API version and spec name.
102+
105103
- If apihub_resource_name includes a spec resource name, the content of that
106104
spec will be used for generating the tools.
107105
- If apihub_resource_name includes only an api or a version name, the
108106
first spec of the first version of that API will be used.
109107
110108
Example:
109+
111110
* projects/xxx/locations/us-central1/apis/apiname/...
112111
* https://console.cloud.google.com/apigee/api-hub/apis/apiname?project=xxx
113112
114113
Args:
115114
apihub_resource_name: The resource name of the API in API Hub.
116-
Example: `projects/test-project/locations/us-central1/apis/test-api`.
117-
access_token: Google Access token. Generate with gcloud cli `gcloud auth
118-
auth print-access-token`. Used for fetching API Specs from API Hub.
115+
Example: ``projects/test-project/locations/us-central1/apis/test-api``.
116+
access_token: Google Access token. Generate with gcloud cli
117+
``gcloud auth auth print-access-token``. Used for fetching API Specs from API Hub.
119118
service_account_json: The service account config as a json string.
120119
Required if not using default service credential. It is used for
121120
creating the API Hub client and fetching the API Specs from API Hub.

src/google/adk/tools/application_integration_tool/application_integration_toolset.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import logging
1618
from typing import List
1719
from typing import Optional
@@ -42,43 +44,39 @@
4244
# TODO(cheliu): Apply a common toolset interface
4345
class ApplicationIntegrationToolset(BaseToolset):
4446
"""ApplicationIntegrationToolset generates tools from a given Application
45-
4647
Integration or Integration Connector resource.
47-
Example Usage:
48-
```
49-
# Get all available tools for an integration with api trigger
50-
application_integration_toolset = ApplicationIntegrationToolset(
5148
52-
project="test-project",
53-
location="us-central1"
54-
integration="test-integration",
55-
triggers=["api_trigger/test_trigger"],
56-
service_account_credentials={...},
57-
)
49+
Example Usage::
5850
59-
# Get all available tools for a connection using entity operations and
60-
# actions
61-
# Note: Find the list of supported entity operations and actions for a
62-
connection
63-
# using integration connector apis:
64-
#
65-
https://cloud.google.com/integration-connectors/docs/reference/rest/v1/projects.locations.connections.connectionSchemaMetadata
66-
application_integration_toolset = ApplicationIntegrationToolset(
67-
project="test-project",
68-
location="us-central1"
69-
connection="test-connection",
70-
entity_operations=["EntityId1": ["LIST","CREATE"], "EntityId2": []],
71-
#empty list for actions means all operations on the entity are supported
72-
actions=["action1"],
73-
service_account_credentials={...},
74-
)
51+
# Get all available tools for an integration with api trigger
52+
application_integration_toolset = ApplicationIntegrationToolset(
53+
project="test-project",
54+
location="us-central1"
55+
integration="test-integration",
56+
triggers=["api_trigger/test_trigger"],
57+
service_account_credentials={...},
58+
)
59+
60+
# Get all available tools for a connection using entity operations and
61+
# actions
62+
# Note: Find the list of supported entity operations and actions for a
63+
# connection using integration connector apis:
64+
# https://cloud.google.com/integration-connectors/docs/reference/rest/v1/projects.locations.connections.connectionSchemaMetadata
65+
application_integration_toolset = ApplicationIntegrationToolset(
66+
project="test-project",
67+
location="us-central1"
68+
connection="test-connection",
69+
entity_operations=["EntityId1": ["LIST","CREATE"], "EntityId2": []],
70+
#empty list for actions means all operations on the entity are supported
71+
actions=["action1"],
72+
service_account_credentials={...},
73+
)
7574
76-
# Feed the toolset to agent
77-
agent = LlmAgent(tools=[
78-
...,
79-
application_integration_toolset,
80-
])
81-
```
75+
# Feed the toolset to agent
76+
agent = LlmAgent(tools=[
77+
...,
78+
application_integration_toolset,
79+
])
8280
"""
8381

8482
def __init__(
@@ -122,11 +120,11 @@ def __init__(
122120
123121
Raises:
124122
ValueError: If none of the following conditions are met:
125-
- `integration` is provided.
126-
- `connection` is provided and at least one of `entity_operations`
127-
or `actions` is provided.
123+
- ``integration`` is provided.
124+
- ``connection`` is provided and at least one of ``entity_operations``
125+
or ``actions`` is provided.
128126
Exception: If there is an error during the initialization of the
129-
integration or connection client.
127+
integration or connection client.
130128
"""
131129
super().__init__(tool_filter=tool_filter)
132130
self.project = project

src/google/adk/tools/application_integration_tool/integration_connector_tool.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ class IntegrationConnectorTool(BaseTool):
4545
* Generates request params and body
4646
* Attaches auth credentials to API call.
4747
48-
Example:
49-
```
48+
Example::
49+
5050
# Each API operation in the spec will be turned into its own tool
5151
# Name of the tool is the operationId of that operation, in snake case
5252
operations = OperationGenerator().parse(openapi_spec_dict)
5353
tool = [RestApiTool.from_parsed_operation(o) for o in operations]
54-
```
5554
"""
5655

5756
EXCLUDE_FIELDS = [

0 commit comments

Comments
 (0)