Skip to content

Conversation

@ashwinb
Copy link
Contributor

@ashwinb ashwinb commented Oct 28, 2025

Error fixes in Agents implementation (meta-reference provider) -- adding proper type annotations and using type narrowing for optional attributes. Essentially a bunch of if x and x_foo := getattr(x, "foo") instead of x.foo directly

Part of ongoing mypy remediation effort.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 28, 2025
@ashwinb ashwinb force-pushed the mypy/01-meta-reference-agents branch from 3cfd312 to e1b67cb Compare October 28, 2025 18:51
@ashwinb ashwinb changed the title fix(mypy): resolve meta reference agent type issues fix(mypy-cleanup): part-01 resolve meta reference agent type issues (126 errors) Oct 28, 2025
@ashwinb ashwinb force-pushed the mypy/01-meta-reference-agents branch 2 times, most recently from 5739ebf to 4fa4309 Compare October 28, 2025 19:01
@ashwinb ashwinb marked this pull request as ready for review October 28, 2025 19:05
ashwinb and others added 4 commits October 28, 2025 13:12
- Add proper type annotations using Any where needed
- Fix union-attr errors with getattr and walrus operator
- Fix arg-type errors for datetime/enum conversions
- Add type: ignore for list invariance issues
- Remove event variable reuse to satisfy type checker
- Use proper type narrowing for tool execution paths

Patterns established:
- Use getattr() with walrus operator for optional attributes
- Use type: ignore for runtime-correct but mypy-incompatible cases
- Separate event variables by type to avoid union conflicts
Fixed 35 errors, 46 remaining:
- Add isinstance() checks for union type discrimination
- Fix list type annotations for Message types
- Convert strings to datetime/StepType where needed
- Use assert to narrow AgentTurnCreateRequest vs AgentTurnResumeRequest
- Add explicit type annotations to avoid inference issues

Still to fix:
- Remaining str to datetime/StepType conversions
- Optional list handling for shields
- Type annotations for tool maps
- List variance issues for input_messages
- Fix turn_id variable redefinition
- Add None checks for optional shield and client_tools lists
- Convert StepType.X.value to StepType.X enum values
- Convert ISO timestamp strings to datetime objects
- Add type annotations (output_attachments, tool_name_to_def)
- Fix union type discrimination with isinstance checks
- Fix max_infer_iters optional comparison
- Filter tool_calls to exclude strings, keep only ToolCall objects
- Fix identifier handling for BuiltinTool enum conversion
- Fix Attachment API parameter (url → content)
- Add type: ignore for OpenAI response format compatibility

Fixes all 81 mypy errors in agent_instance.py.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ashwinb ashwinb force-pushed the mypy/01-meta-reference-agents branch from 6822dec to 2882ae3 Compare October 28, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants