Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 2, 2025

Problem

The Smart Decision Maker block was generating duplicate tool names when multiple blocks of the same type (e.g., two StoreValueBlocks) or agents with the same graph were connected to it. This caused the Anthropic API to reject requests with the error:

[LLM-Block] Anthropic API error: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'tools: Tool names must be unique.'}, 'request_id': 'req_011CSZ4DYHkHMoqygo6q3xyw'}

Root Cause: The tool naming logic used only the block name (block.name) or graph name (sink_graph_meta.name), which resulted in identical tool names for multiple instances of the same block type.

Solution

Implemented a three-tier naming strategy that ensures unique tool names while respecting user customization:

For Block Nodes:

  1. First Priority: Use customized_name from node metadata (when user renames the block in the UI)
  2. Fallback: Generate {block_name}_{node_id_prefix} where node_id_prefix is the first 8 characters of the node's UUID

For Agent Nodes:

  1. First Priority: Use customized_name from node metadata
  2. Second Priority: Use agent_name from the node's input configuration
  3. Fallback: Generate {graph_name}_{node_id_prefix}

Example:

Before (causes error):

[
  {"name": "storevalueblock", "description": "..."},
  {"name": "storevalueblock", "description": "..."}  // ❌ Duplicate!
]

After (unique names):

[
  {"name": "storevalueblock_a1b2c3d4", "description": "..."},
  {"name": "storevalueblock_e5f6g7h8", "description": "..."}  // ✅ Unique!
]

With user customization:

[
  {"name": "save_user_data", "description": "..."},     // User renamed block
  {"name": "save_api_response", "description": "..."}   // User renamed block
]

Changes

Backend (smart_decision_maker.py)

  • Modified _create_block_function_signature() to use metadata-based naming with UUID fallback
  • Modified _create_agent_function_signature() to prioritize customized names and agent_name
  • Both methods now guarantee unique tool names for Anthropic API compliance

Frontend (useAgentGraph.tsx)

  • Updated getToolFuncName() to match backend naming logic
  • Ensures frontend generates the same tool names when creating link source names

Tests

  • Updated test_smart_decision_maker_function_signature to expect node ID suffixes
  • Added test_smart_decision_maker_unique_tool_names_for_duplicate_blocks to verify uniqueness
  • Fixed mock node setup in test_smart_decision_maker_dict.py

Benefits

Resolves Anthropic API error: Tool names are now guaranteed to be unique
Backward compatible: Works with OpenAI and other LLM providers
User-friendly: Respects user-customized block names from metadata
Deterministic: Node ID suffixes ensure consistent naming across runs
Minimal changes: Only affects naming logic, no changes to execution flow

Testing

All 8 smart decision maker tests pass, including the new test specifically for duplicate block handling.

Fixes #10761

Original prompt

Issue Title: [BUG] The smart decsison maker block cannot output datastructures to two different dictionary formats
Issue Description: Sentry Issue: AUTOGPT-SERVER-5BA

�[31m[LLM-Block] Anthropic API error: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'tools: Tool names must be unique.'}, 'request_id': 'req_011CSZ4DYHkHMoqygo6q3xyw'} �[0m

The issue here is that Anthropic doesn't allow multiple tools to have the same name, and we don't have this restriction. We should probably dynamically name the tools in a deterministic but non-conflicting manner to avoid this issue for users, as I thought this would work.

With the introduction of renaming blocks, we should check if the block has been renamed and use that metadata (front end shows where its stored) and build based on that.

Example Agent format:

image.png
Fixes https://linear.app/autogpt/issue/OPEN-2662/bug-the-smart-decsison-maker-block-cannot-output-datastructures-to-two

Comment by User :
This thread is for an agent session with githubcopilotcodingagent.

Comment by User :
This thread is for an agent session with githubcopilotcodingagent.

Comment by User 055a3053-5ab6-449a-bcfa-990768594185:
probably a claude fix

Comment by User 055a3053-5ab6-449a-bcfa-990768594185:
new work done on adding block renaming unblocks this!

Comment by User 264d7bf4-db2a-46fa-a880-7d67b58679e6:
@ntindle same thing for this bug on smart decision block if its worth doing now.

Comment by User :
This comment thread is synced to a corresponding GitHub issue. All replies are displayed in both locations.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 8d6b944
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs/deploys/68e023bd6073f40008ebc978

Copy link

deepsource-io bot commented Oct 2, 2025

Here's the code health analysis summary for commits 7f8cf36..8d6b944. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript✅ SuccessView Check ↗
DeepSource Python LogoPython✅ Success
❗ 3 occurences introduced
🎯 3 occurences resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

- Use customized_name from node metadata when available
- Fallback to block/graph name with node ID suffix for uniqueness
- Update frontend getToolFuncName to match backend logic
- Add test to verify unique tool names for duplicate blocks
- Fixes Anthropic API error when multiple blocks of same type are used

Co-authored-by: ntindle <[email protected]>
@AutoGPT-Agent
Copy link

Thanks for working on this fix for the duplicate tool names issue with Smart Decision Maker! The implementation looks solid, adding appropriate unique identifiers to tool names when needed.

Before this can be merged:

  1. The PR title needs to be updated to follow the conventional commit format. Since you're fixing an issue with Anthropic API rejecting duplicate tool names, something like fix(backend): ensure unique tool names for Smart Decision Maker would be appropriate.

  2. Since this is marked as WIP, is there any other work that still needs to be completed before this is ready for review?

The implementation approach looks good - using customized_name when available and falling back to adding node ID suffixes is a clean solution. I particularly appreciate the comprehensive test case you added to verify uniqueness when duplicate blocks are used.

@AutoGPT-Agent
Copy link

Thanks for working on this issue! Here's some feedback to get this PR ready for merging:

  1. The PR title needs to follow conventional commit format. Consider updating it to something like: fix(platform/backend): prevent duplicate tool names in Smart Decision Maker

  2. The PR is currently marked as WIP. Once you've completed the work, please remove the WIP tag.

  3. The implementation looks good - using customized_name from metadata when available and falling back to a unique identifier with node ID suffix is a solid approach.

  4. The tests you've added look comprehensive and should help prevent regression.

Once you've addressed these items, particularly updating the PR title to follow conventional commit format and removing the WIP tag when ready, this should be good to go!

- Set mock_node.metadata = {} to avoid Mock object being returned
- Set mock_node.id to provide fallback naming for tests
- All smart decision maker tests now pass

Co-authored-by: ntindle <[email protected]>
@AutoGPT-Agent
Copy link

Thank you for your PR addressing the duplicate tool names issue with the Smart Decision Maker block. The implementation looks good, using the customized_name from metadata when available and falling back to node ID suffixes for uniqueness.

Before this can be merged:

  1. Please update the PR title to follow the conventional commit format. Since this is fixing a bug with the Smart Decision Maker block, something like fix(backend): resolve duplicate tool names in Smart Decision Maker would be appropriate.

  2. Remove the [WIP] tag when the PR is ready for review and merging.

  3. Consider adding a brief explanation in the PR description about how the solution handles backward compatibility for existing agents.

Your implementation looks solid and the tests are thorough. The approach of using customized names when available and falling back to node ID suffixes is a good solution that addresses the issue while maintaining readability.

@AutoGPT-Agent
Copy link

Thanks for this PR addressing the duplicate tool names issue with the Smart Decision Maker block. The implementation looks solid and I appreciate the comprehensive test coverage.

Before this can be merged:

  1. The PR title needs to be updated to follow our conventional commit format. Since this is fixing a bug in the backend, something like fix(backend): Prevent duplicate tool names in Smart Decision Maker would be appropriate.

  2. Since this is marked as [WIP], is there anything else you're planning to add before this is ready for final review?

The implementation approach looks sound:

  • Using customized_name from metadata when available
  • Creating unique names by appending node ID segments as fallback
  • Ensuring consistent naming logic between backend and frontend
  • Adding good test coverage for the new functionality

Once the title is updated and you confirm this is ready for review (by removing [WIP]), this PR should be good to go!

@Copilot Copilot AI changed the title [WIP] Copilot Request Fix duplicate tool names in Smart Decision Maker block for Anthropic API compatibility Oct 2, 2025
@Copilot Copilot AI requested a review from ntindle October 2, 2025 21:18
Copilot finished work on behalf of ntindle October 2, 2025 21:18
@github-actions github-actions bot added platform/frontend AutoGPT Platform - Front end platform/blocks size/l labels Oct 2, 2025
@ntindle ntindle changed the base branch from master to dev October 2, 2025 21:20
@ntindle
Copy link
Member

ntindle commented Oct 2, 2025

@coderabbitai review

@ntindle
Copy link
Member

ntindle commented Oct 2, 2025

@claude make sure this is high quality

Copy link
Contributor

claude bot commented Oct 2, 2025

Claude finished @ntindle's task —— View job


Working on code review...

Todo List

  • Read and analyze backend changes in smart_decision_maker.py
  • Review test updates and new test cases
  • Examine frontend changes for consistency
  • Check for edge cases and potential issues
  • Provide comprehensive review feedback

Code Review Analysis

After reviewing the PR thoroughly, here's my assessment:

✅ Strengths

  1. Robust Solution: The implementation properly addresses the duplicate tool names issue using a well-thought-out three-tier naming strategy that prioritizes user customization while ensuring uniqueness.

  2. Comprehensive Test Coverage: The new test test_smart_decision_maker_unique_tool_names_for_duplicate_blocks specifically validates the fix, and existing tests have been properly updated to accommodate the changes.

  3. Frontend-Backend Consistency: The frontend getToolFuncName() function mirrors the backend naming logic, ensuring consistency across the application.

  4. Backward Compatibility: The solution maintains compatibility with existing agents and graphs while fixing the Anthropic API issue.

📝 Suggestions for Improvement

1. Minor Code Organization

In smart_decision_maker.py, lines 286-293 and 368-379, consider extracting the node ID suffix generation into a helper method to reduce duplication:

@staticmethod
def _get_node_suffix(node_id: str) -> str:
    """Get the first segment of UUID for unique suffix."""
    return node_id.split("-")[0]

2. Documentation Enhancement

Consider adding a docstring comment explaining the naming strategy at the class level or in the _create_block_function_signature and _create_agent_function_signature methods to help future maintainers understand the rationale.

3. Test Assertions

In test_smart_decision_maker_unique_tool_names_for_duplicate_blocks (line 566), the assertion for hex string validation could be more robust:

# Verify it's a valid hex string
try:
    int(parts[1], 16)
except ValueError:
    pytest.fail(f"Node ID segment should be hex, got {parts[1]}")

4. Edge Case Consideration

The current implementation uses the first 8 characters of the UUID. While collision is extremely unlikely, consider documenting this limitation or adding a collision check if critical.

✅ Overall Assessment

This is a high-quality fix that:

  • Correctly solves the Anthropic API error
  • Maintains clean, readable code
  • Includes proper test coverage
  • Preserves backward compatibility

The implementation is production-ready. The suggestions above are minor improvements that would enhance code maintainability but are not blockers.

Great work on this fix! 👍


@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Oct 3, 2025
Copy link
Contributor

github-actions bot commented Oct 3, 2025

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

Copy link

netlify bot commented Oct 3, 2025

Deploy Preview for auto-gpt-docs-dev canceled.

Name Link
🔨 Latest commit 8d6b944
🔍 Latest deploy log https://app.netlify.com/projects/auto-gpt-docs-dev/deploys/68e023bd8201e300085f1932

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Oct 3, 2025
Copy link
Contributor

github-actions bot commented Oct 3, 2025

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🆕 Needs initial review
Status: No status
Development

Successfully merging this pull request may close these issues.

[BUG] The smart decsison maker block cannot output datastructures to two different dictionary formats
3 participants