Skip to content

Commit 38209c6

Browse files
committed
[Temporal - Documentation] Fixing PR errors
1 parent f2fb561 commit 38209c6

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

examples/pydantic_ai_examples/temporal_streaming/agents.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
and custom tools for data analysis.
55
"""
66
from datetime import timedelta
7+
from typing import Any
78

89
from temporalio.common import RetryPolicy
910
from temporalio.workflow import ActivityConfig
@@ -17,7 +18,7 @@
1718
from .datamodels import AgentDependencies
1819

1920

20-
async def get_mcp_toolsets() -> dict[str, FilteredToolset]:
21+
async def get_mcp_toolsets() -> dict[str, FilteredToolset[AgentDependencies]]:
2122
"""
2223
Initialize MCP toolsets for the agent.
2324
@@ -34,7 +35,7 @@ async def get_mcp_toolsets() -> dict[str, FilteredToolset]:
3435
return {'yahoo': yf_server.filtered(lambda ctx, tool_def: True)}
3536

3637

37-
async def get_claude_model(parallel_tool_calls: bool = True, **kwargs):
38+
async def get_claude_model(parallel_tool_calls: bool = True, **kwargs: Any) -> AnthropicModel:
3839
"""
3940
Create and configure the Claude model.
4041
@@ -60,8 +61,8 @@ async def get_claude_model(parallel_tool_calls: bool = True, **kwargs):
6061
return model
6162

6263

63-
async def build_agent(stream_handler: EventStreamHandler,
64-
**kwargs) -> TemporalAgent:
64+
async def build_agent(stream_handler: EventStreamHandler[AgentDependencies],
65+
**kwargs: Any) -> TemporalAgent[AgentDependencies, str]:
6566
"""
6667
Build and configure the agent with tools and temporal settings.
6768
@@ -78,7 +79,7 @@ async def build_agent(stream_handler: EventStreamHandler,
7879
agent_name = 'YahooFinanceSearchAgent'
7980

8081
toolsets = await get_mcp_toolsets()
81-
agent = Agent(
82+
agent: Agent[AgentDependencies, str] = Agent[AgentDependencies, str](
8283
name=agent_name,
8384
model=await get_claude_model(**kwargs),
8485
toolsets=[*toolsets.values()],

examples/pydantic_ai_examples/temporal_streaming/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ async def poll_events(workflow_handle: WorkflowHandle[Any, str]) -> None:
2828
workflow_handle: Handle to the running workflow.
2929
"""
3030
while True:
31-
event = await workflow_handle.query('event_stream', result_type=Union[EventStream | None])
31+
event: Union[EventStream, None] = await workflow_handle.query('event_stream',
32+
result_type=Union[
33+
EventStream, None]) # type: ignore[misc]
3234
if event is None:
3335
await asyncio.sleep(0.1)
3436
continue
@@ -55,6 +57,7 @@ async def main() -> None:
5557
"""
5658
# Connect to Temporal server
5759
client = await Client.connect(
60+
# target_host='localhost:7233',
5861
target_host='localhost:7233',
5962
plugins=[PydanticAIPlugin()],
6063
)
@@ -77,7 +80,7 @@ async def main() -> None:
7780
):
7881
# Execute the workflow
7982
workflow_id = f'yahoo-finance-search-{uuid.uuid4()}'
80-
workflow_handle: WorkflowHandle[Any, str] = await client.start_workflow(
83+
workflow_handle: WorkflowHandle[Any, str] = await client.start_workflow( # type: ignore[misc]
8184
'YahooFinanceSearchWorkflow',
8285
arg='What are the latest financial metrics for Apple (AAPL)?',
8386
id=workflow_id,

examples/pydantic_ai_examples/temporal_streaming/streaming_handler.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
async def streaming_handler(
27-
ctx: RunContext,
27+
ctx: RunContext[AgentDependencies],
2828
event_stream_events: AsyncIterable[AgentStreamEvent],
2929
) -> None:
3030
"""
@@ -74,18 +74,25 @@ async def streaming_handler(
7474
if len(output_tool_delta['tool_call_id']) == 0:
7575
output_tool_delta['tool_call_id'] += event.delta.tool_call_id or ''
7676
output_tool_delta['tool_name_delta'] += event.delta.tool_name_delta or ''
77-
output_tool_delta['args_delta'] += event.delta.args_delta or ''
77+
# Handle args_delta which can be str or dict
78+
args_delta = event.delta.args_delta
79+
if isinstance(args_delta, str):
80+
output_tool_delta['args_delta'] += args_delta
81+
elif isinstance(args_delta, dict):
82+
output_tool_delta['args_delta'] += str(args_delta)
7883

7984
# Add accumulated tool delta output if present
8085
if len(output_tool_delta['tool_call_id']):
8186
output += f'\nTool Call Id: {output_tool_delta["tool_call_id"]}'
8287
output += f'\nTool Name: {output_tool_delta["tool_name_delta"]}'
83-
output += f'\nTool Args: {output_tool_delta["args_delta"]}'
88+
args_delta_str = str(output_tool_delta["args_delta"])
89+
output += f'\nTool Args: {args_delta_str}'
8490

8591
# Send events to workflow if running in an activity
8692
deps: AgentDependencies = ctx.deps
8793

8894
workflow_id: str = deps.workflow_id
8995
run_id: str = deps.run_id
90-
workflow_handle: WorkflowHandle = activity.client().get_workflow_handle(workflow_id=workflow_id, run_id=run_id)
96+
from typing import Any
97+
workflow_handle: WorkflowHandle[Any, Any] = activity.client().get_workflow_handle(workflow_id=workflow_id, run_id=run_id) # type: ignore[misc]
9198
await workflow_handle.signal('append_event', arg=EventStream(kind=EventKind.EVENT, content=output))

examples/pydantic_ai_examples/temporal_streaming/utils.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import yaml
88

99

10-
def recursively_modify_api_key(conf) -> dict[str, Any]:
10+
def recursively_modify_api_key(conf: dict[str, Any]) -> dict[str, Any]:
1111
"""
1212
Recursively replace API key placeholders with environment variable values.
1313
@@ -22,16 +22,17 @@ def recursively_modify_api_key(conf) -> dict[str, Any]:
2222
A copy of the configuration with API keys replaced by environment variable values.
2323
"""
2424

25-
def inner(_conf):
25+
def inner(_conf: dict[str, Any]) -> None:
2626
for key, value in _conf.items():
2727
if isinstance(value, dict):
28-
inner(value)
28+
inner(value) # type: ignore[arg-type]
2929
elif isinstance(value, list):
30-
if len(value) > 0 and isinstance(value[0], dict):
31-
for item in value:
32-
inner(item)
30+
if len(value) > 0 and isinstance(value[0], dict): # type: ignore[misc]
31+
item: dict[str, Any]
32+
for item in value: # type: ignore[assignment,misc]
33+
inner(item) # type: ignore[arg-type]
3334
else:
34-
_conf[key] = [os.environ.get(str(v), v) for v in value]
35+
_conf[key] = [str(os.environ.get(str(v), v)) for v in value] # type: ignore[misc]
3536
elif isinstance(value, str):
3637
_conf[key] = os.environ.get(value, value)
3738
else:
@@ -42,7 +43,7 @@ def inner(_conf):
4243
return copy_conf
4344

4445

45-
def read_config_yml(path) -> dict[str, Any]:
46+
def read_config_yml(path: str) -> dict[str, Any]:
4647
"""
4748
Read and process a YAML configuration file.
4849

examples/pydantic_ai_examples/temporal_streaming/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def run(self, user_prompt: str) -> str:
4444
The agent's final output.
4545
"""
4646
# Retrieve environment variables from configuration
47-
wf_vars = await workflow.execute_activity(
47+
wf_vars = await workflow.execute_activity( # type: ignore[misc]
4848
activity='retrieve_env_vars',
4949
start_to_close_timeout=timedelta(seconds=10),
5050
result_type=dict[str, Any],

0 commit comments

Comments
 (0)