Skip to content

fix(beta/network): resolve namespaced and enumerate unknown delegate targets#3005

Open
genisis0x wants to merge 1 commit into
ag2ai:mainfrom
genisis0x:fix/delegate-functions-prefix
Open

fix(beta/network): resolve namespaced and enumerate unknown delegate targets#3005
genisis0x wants to merge 1 commit into
ag2ai:mainfrom
genisis0x:fix/delegate-functions-prefix

Conversation

@genisis0x

@genisis0x genisis0x commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Why are these changes needed?

A delegate target that doesn't resolve sends the run into a retry loop: the model gets a bare Error: target ... not found, re-guesses, and in multi-agent pipelines stalls out (reported in #3022, an extension of #2991 / #2998). The delegate call itself fails fast (~0.6ms in the telemetry on #3022) — the timeout is the model never converging on a real target.

This addresses both flavours of that loop:

1. Namespaced-but-valid targets. LLMs occasionally echo OpenAI's functions. tool namespace into the target string — e.g. functions.evaluator instead of evaluator. The literal name misses the hub registry, so the consult would fail even though the peer is real. Resolution now tries candidate names most-literal first: the name as given, then — only when it carries the functions. prefix — the unprefixed name. A valid peer behind a namespaced target resolves and the consult proceeds. The channel is opened with the resolved name.

2. Fully invented targets. When no strip recovers the name (e.g. PPTDialogScript), the model has no signal about which peers are real, so it keeps re-guessing. The not-found error now enumerates the live directory — Error: target 'PPTDialogScript' not found. Available targets: [evaluator, translator] — so the next turn can pick a real one. The lookup is best-effort: a directory failure falls back to the bare not-found error, and the caller is excluded since self-delegation is rejected anyway.

Genuinely unknown targets still fail fast (now with the available-targets hint), and self-delegation still short-circuits as added in #2998.

Related issue number

Closes #3022

Checks

  • I've included any doc changes needed for https://docs.ag2.ai/.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed.

AI assistance

  • I understand the changes in this PR and can explain them in my own words.
  • I have verified that the PR description accurately reflects the actual diff.
  • If AI assistance was used, I reviewed, tested, and validated the generated code/text before submitting.

@genisis0x
genisis0x requested a review from Lancetnik as a code owner June 23, 2026 07:08
@github-actions github-actions Bot added the beta label Jun 23, 2026
@genisis0x genisis0x changed the title fix(beta/network): resolve functions.-prefixed delegate targets fix(beta/network): resolve namespaced and enumerate unknown delegate targets Jun 26, 2026
LLMs sometimes echo OpenAI's "functions." tool namespace into a
delegate target (e.g. "functions.evaluator"), so the literal name
misses the registry, the consult fails, and the model re-guesses into a
stalled run. Try the literal name first, then the name with the
"functions." prefix stripped.

When a target still does not resolve, return the live peer names in the
not-found error (excluding the caller, which cannot be a delegate
target) so the next turn can pick a real one instead of inventing
another name. The directory lookup is best-effort and never masks the
original error.

Adds regression tests for both paths.
@genisis0x
genisis0x force-pushed the fix/delegate-functions-prefix branch from 26eaed7 to 5ad911f Compare June 29, 2026 06:55
@Lancetnik Lancetnik added type:bug Existing behavior is broken or doesn't match the docs area:network Agent network (ag2/network) status:needs-review PR is ready and waiting for maintainer review and removed beta labels Jul 4, 2026
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ag2/network/client/tools/delegate.py 88.00% 2 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
ag2/network/client/tools/delegate.py 81.08% <88.00%> (+4.15%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@genisis0x

Copy link
Copy Markdown
Contributor Author

@Lancetnik whenever the network-area queue allows, no rush — this one's green and folds the durable half of #3022: the enumerate-unknown-delegate-targets change, so a not-found delegate now returns an error listing the live registered peers instead of letting the model keep hallucinating a target until it times out. Happy to rebase if it's drifted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:network Agent network (ag2/network) status:needs-review PR is ready and waiting for maintainer review type:bug Existing behavior is broken or doesn't match the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Delegate is still hallucinating functions causing it to timeout

2 participants