Skip to content

Commit c416370

Browse files
authored
Merge pull request #5 from TGreen87/codex/fix-comments-lacking-trailing-periods
Fix comments to end with periods
2 parents 5d2d616 + 66bf69b commit c416370

32 files changed

+217
-228
lines changed

src/agents/_run_impl.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ProcessedResponse:
134134
tools_used: list[str] # Names of all tools used, including hosted tools
135135

136136
def has_tools_to_run(self) -> bool:
137-
# Handoffs, functions and computer actions need local processing
137+
# Handoffs, functions, and computer actions need local processing.
138138
# Hosted tools have already run, so there's nothing to do.
139139
return any(
140140
[
@@ -202,9 +202,9 @@ async def execute_tools_and_side_effects(
202202
cls,
203203
*,
204204
agent: Agent[TContext],
205-
# The original input to the Runner
205+
# The original input to the Runner.
206206
original_input: str | list[TResponseInputItem],
207-
# Everything generated by Runner since the original input, but before the current step
207+
# Everything generated by Runner since the original input, but before the current step.
208208
pre_step_items: list[RunItem],
209209
new_response: ModelResponse,
210210
processed_response: ProcessedResponse,
@@ -213,13 +213,13 @@ async def execute_tools_and_side_effects(
213213
context_wrapper: RunContextWrapper[TContext],
214214
run_config: RunConfig,
215215
) -> SingleStepResult:
216-
# Make a copy of the generated items
216+
# Make a copy of the generated items.
217217
pre_step_items = list(pre_step_items)
218218

219219
new_step_items: list[RunItem] = []
220220
new_step_items.extend(processed_response.new_items)
221221

222-
# First, lets run the tool calls - function tools and computer actions
222+
# First, let us run the tool calls: function tools and computer actions.
223223
function_results, computer_results = await asyncio.gather(
224224
cls.execute_function_tool_calls(
225225
agent=agent,
@@ -239,7 +239,7 @@ async def execute_tools_and_side_effects(
239239
new_step_items.extend([result.run_item for result in function_results])
240240
new_step_items.extend(computer_results)
241241

242-
# Second, check if there are any handoffs
242+
# Second, check whether there are any handoffs.
243243
if run_handoffs := processed_response.handoffs:
244244
return await cls.execute_handoffs(
245245
agent=agent,
@@ -253,7 +253,7 @@ async def execute_tools_and_side_effects(
253253
run_config=run_config,
254254
)
255255

256-
# Third, we'll check if the tool use should result in a final output
256+
# Third, we check whether the tool use should result in a final output.
257257
check_tool_use = await cls._check_for_final_output_from_tools(
258258
agent=agent,
259259
tool_results=function_results,
@@ -262,7 +262,7 @@ async def execute_tools_and_side_effects(
262262
)
263263

264264
if check_tool_use.is_final_output:
265-
# If the output type is str, then let's just stringify it
265+
# If the output type is str, then just stringify it.
266266
if not agent.output_type or agent.output_type is str:
267267
check_tool_use.final_output = str(check_tool_use.final_output)
268268

@@ -283,17 +283,17 @@ async def execute_tools_and_side_effects(
283283
context_wrapper=context_wrapper,
284284
)
285285

286-
# Now we can check if the model also produced a final output
286+
# Now we can check whether the model also produced a final output.
287287
message_items = [item for item in new_step_items if isinstance(item, MessageOutputItem)]
288288

289-
# We'll use the last content output as the final output
289+
# We use the last content output as the final output.
290290
potential_final_output_text = (
291291
ItemHelpers.extract_last_text(message_items[-1].raw_item) if message_items else None
292292
)
293293

294-
# There are two possibilities that lead to a final output:
295-
# 1. Structured output schema => always leads to a final output
296-
# 2. Plain text output schema => only leads to a final output if there are no tool calls
294+
# There are two possibilities that lead to a final output.
295+
# 1. Structured output schema always leads to a final output.
296+
# 2. Plain text output schema leads to a final output only if there are no tool calls.
297297
if output_schema and not output_schema.is_plain_text() and potential_final_output_text:
298298
final_output = output_schema.validate_json(potential_final_output_text)
299299
return await cls.execute_final_output(
@@ -320,7 +320,7 @@ async def execute_tools_and_side_effects(
320320
context_wrapper=context_wrapper,
321321
)
322322
else:
323-
# If there's no final output, we can just run again
323+
# If there is no final output, we can run again.
324324
return SingleStepResult(
325325
original_input=original_input,
326326
model_response=new_response,
@@ -392,21 +392,21 @@ def process_model_response(
392392
logger.warning(f"Unexpected output type, ignoring: {type(output)}")
393393
continue
394394

395-
# At this point we know it's a function tool call
395+
# At this point we know it is a function tool call.
396396
if not isinstance(output, ResponseFunctionToolCall):
397397
continue
398398

399399
tools_used.append(output.name)
400400

401-
# Handoffs
401+
# Handoffs.
402402
if output.name in handoff_map:
403403
items.append(HandoffCallItem(raw_item=output, agent=agent))
404404
handoff = ToolRunHandoff(
405405
tool_call=output,
406406
handoff=handoff_map[output.name],
407407
)
408408
run_handoffs.append(handoff)
409-
# Regular function tool call
409+
# Regular function tool call.
410410
else:
411411
if output.name not in function_map:
412412
_error_tracing.attach_error_to_current_span(
@@ -513,7 +513,7 @@ async def execute_computer_actions(
513513
config: RunConfig,
514514
) -> list[RunItem]:
515515
results: list[RunItem] = []
516-
# Need to run these serially, because each action can affect the computer state
516+
# These must run serially because each action can affect the computer state.
517517
for action in actions:
518518
results.append(
519519
await ComputerAction.execute(
@@ -541,7 +541,7 @@ async def execute_handoffs(
541541
context_wrapper: RunContextWrapper[TContext],
542542
run_config: RunConfig,
543543
) -> SingleStepResult:
544-
# If there is more than one handoff, add tool responses that reject those handoffs
544+
# If there is more than one handoff, add tool responses that reject those handoffs.
545545
multiple_handoffs = len(run_handoffs) > 1
546546
if multiple_handoffs:
547547
output_message = "Multiple handoffs detected, ignoring this one."
@@ -576,7 +576,7 @@ async def execute_handoffs(
576576
)
577577
)
578578

579-
# Append a tool output item for the handoff
579+
# Append a tool output item for the handoff.
580580
new_step_items.append(
581581
HandoffOutputItem(
582582
agent=agent,
@@ -589,7 +589,7 @@ async def execute_handoffs(
589589
)
590590
)
591591

592-
# Execute handoff hooks
592+
# Execute handoff hooks.
593593
await asyncio.gather(
594594
hooks.on_handoff(
595595
context=context_wrapper,
@@ -607,7 +607,7 @@ async def execute_handoffs(
607607
),
608608
)
609609

610-
# If there's an input filter, filter the input for the next agent
610+
# If there is an input filter, filter the input for the next agent.
611611
input_filter = handoff.input_filter or (
612612
run_config.handoff_input_filter if run_config else None
613613
)
@@ -669,7 +669,7 @@ async def execute_final_output(
669669
hooks: RunHooks[TContext],
670670
context_wrapper: RunContextWrapper[TContext],
671671
) -> SingleStepResult:
672-
# Run the on_end hooks
672+
# Run the on_end hooks.
673673
await cls.run_final_output_hooks(agent, hooks, context_wrapper, final_output)
674674

675675
return SingleStepResult(
@@ -862,22 +862,22 @@ async def execute(
862862
),
863863
)
864864

865-
# Cache screenshots to avoid resending duplicate images.
866-
image_id, is_new = _cache_screenshot(output)
867-
if is_new:
868-
image_url = f"data:image/png;base64,{output}"
869-
raw_output = {
870-
"type": "computer_screenshot",
871-
"image_url": image_url,
872-
"image_id": image_id,
873-
}
874-
final_output = image_url
875-
else:
876-
raw_output = {
877-
"type": "computer_screenshot_ref",
878-
"image_id": image_id,
879-
}
880-
final_output = image_id
865+
# TODO: Cache screenshots; avoid resending duplicate images.
866+
image_id, is_new = _cache_screenshot(output)
867+
if is_new:
868+
image_url = f"data:image/png;base64,{output}"
869+
raw_output = {
870+
"type": "computer_screenshot",
871+
"image_url": image_url,
872+
"image_id": image_id,
873+
}
874+
final_output = image_url
875+
else:
876+
raw_output = {
877+
"type": "computer_screenshot_ref",
878+
"image_id": image_id,
879+
}
880+
final_output = image_id
881881
return ToolCallOutputItem(
882882
agent=agent,
883883
output=final_output,

src/agents/agent_output.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ def __init__(self, output_type: type[Any], strict_json_schema: bool = True):
9292
self._output_schema = self._type_adapter.json_schema()
9393
return
9494

95-
# We should wrap for things that are not plain text, and for things that would definitely
96-
# not be a JSON Schema object.
95+
# We should wrap for things that are not plain text and for things that would definitely not be a JSON Schema object.
9796
self._is_wrapped = not _is_subclass_of_base_model_or_dict(output_type)
9897

9998
if self._is_wrapped:
@@ -172,11 +171,11 @@ def _is_subclass_of_base_model_or_dict(t: Any) -> bool:
172171
if not isinstance(t, type):
173172
return False
174173

175-
# If it's a generic alias, 'origin' will be the actual type, e.g. 'list'
174+
# If it is a generic alias, 'origin' will be the actual type, e.g. 'list'.
176175
origin = get_origin(t)
177176

178177
allowed_types = (BaseModel, dict)
179-
# If it's a generic alias e.g. list[str], then we should check the origin type i.e. list
178+
# If it is a generic alias, e.g. list[str], then we should check the origin type, i.e. list.
180179
return issubclass(origin or t, allowed_types)
181180

182181

src/agents/extensions/handoff_prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# A recommended prompt prefix for agents that use handoffs. We recommend including this or
2-
# similar instructions in any agents that use handoffs.
1+
# A recommended prompt prefix for agents that use handoffs.
2+
# We recommend including this or similar instructions in any agents that use handoffs.
33
RECOMMENDED_PROMPT_PREFIX = (
44
"# System context\n"
55
"You are part of a multi-agent system called the Agents SDK, designed to make agent "

src/agents/extensions/visualization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def get_all_nodes(agent: Agent, parent: Optional[Agent] = None) -> str:
4343
"""
4444
parts = []
4545

46-
# Start and end the graph
46+
# Start and end the graph.
4747
parts.append(
4848
'"__start__" [label="__start__", shape=ellipse, style=filled, '
4949
"fillcolor=lightblue, width=0.5, height=0.3];"
5050
'"__end__" [label="__end__", shape=ellipse, style=filled, '
5151
"fillcolor=lightblue, width=0.5, height=0.3];"
5252
)
53-
# Ensure parent agent node is colored
53+
# Ensure the parent agent node is colored.
5454
if not parent:
5555
parts.append(
5656
f'"{agent.name}" [label="{agent.name}", shape=box, style=filled, '

0 commit comments

Comments
 (0)