Skip to content

fix(tool): omit injected state from inferred function schemas - #3090

Merged
DavdGao merged 3 commits into
agentscope-ai:mainfrom
quifox:fix/functiontool-state-injection
Oct 8, 2026
Merged

DavdGao merged 3 commits into
agentscope-ai:mainfrom
quifox:fix/functiontool-state-injection

Conversation

@quifox

@quifox quifox commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope Version

2.0.10dev (base commit 72f3f6fa0b2fc38b8517f408ab616f0f2bd229e6).

Description

Fixes #3089.

Creating a FunctionTool with is_state_injected=True currently raises NameError when the function declares _agent_state: automatic schema inference tries to create a Pydantic field with a leading underscore. Omit _agent_state during inference when state injection is enabled, keeping the business parameters in the schema. Explicit input schemas retain their existing behavior.

The regression test checks the complete inferred schema and calls the tool through Toolkit, verifying that it receives the same AgentState instance and returns the expected response.

Validation:

  • python -m pytest tests/toolkit_test.py tests/tool_lazy_annotations_test.py tests/tool_middleware_test.py tests/tool_argument_repair_test.py tests/tool_group_ownership_test.py -q: 45 passed, 8 subtests passed. The new regression fails with the expected NameError before the fix.
  • pre-commit run --all-files: passed.
  • python -m pytest tests -q -ra --tb=short: 2634 passed, 125 skipped, 532 subtests passed.

Checklist

  • An issue has been created for this PR
  • I have read the CONTRIBUTING.md
  • Docstrings are in Google style
  • Related documentation has been updated in the FunctionTool constructor docstring; no separate documentation repository update is needed for this bug fix
  • Code is ready for review

@github-actions github-actions Bot added the pr/awaiting-review Waiting for maintainers to review this PR label Oct 2, 2026
@DavdGao
DavdGao merged commit f0177cf into agentscope-ai:main Oct 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr/awaiting-review Waiting for maintainers to review this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: FunctionTool cannot infer schemas for state-injected functions

2 participants