Skip to content

feat: add 'key' parameter to getConnectedAgents API for orchestral/flow modes#856

Open
Husainbw786 wants to merge 2 commits intotestingfrom
feat/connected-agents-flow-type
Open

feat: add 'key' parameter to getConnectedAgents API for orchestral/flow modes#856
Husainbw786 wants to merge 2 commits intotestingfrom
feat/connected-agents-flow-type

Conversation

@Husainbw786
Copy link
Copy Markdown
Collaborator

What changed

Added a new key query parameter to the getConnectedAgents API endpoint (GET /connected-agents/:version_id).

New Parameter

  • key (optional): Accepts orchestral (default) or flow

Behavior

  • orchestral (default): Existing behavior — returns only child agents (agents called by the given agent)
  • flow: Returns all connected agents including:
    • Child agents (agents that the given agent calls)
    • Parent agents (agents that call the given agent)
    • All indirect connections (recursively traverses the entire connection graph)

Why

The existing API only returned the flow of child agents. This update ensures no connected agent is missed by:

  1. Preserving backward compatibility with the default orchestral mode
  2. Adding flow mode that traverses both parent and child relationships
  3. Using a visited set with direction tracking to prevent infinite loops while ensuring all connections are captured

Files Changed

  • src/controllers/agentVersion.controller.js: Added key parameter extraction from query
  • src/db_services/agentVersion.service.js: Updated getAllConnectedAgents with bidirectional traversal logic
  • src/validation/joi_validation/bridgeVersion.validation.js: Added key parameter validation

API Usage

GET /agent-version/connected-agents/:version_id?key=orchestral  # existing behavior
GET /agent-version/connected-agents/:version_id?key=flow        # full connection graph

…ow modes

- orchestral (default): existing behavior, returns child agents only
- flow: returns all connected agents including parents and children
- Traverses both parent and child relationships recursively
- No connected agent is missed in flow mode
Copy link
Copy Markdown
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other comments (1)

💡 To request another review, post a new comment with "/windsurf-review".

}

async function processAgent(agentId, parentIds = [], docType = null, direction = "down") {
const visitKey = `${agentId}-${direction}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The visitKey combines agentId and direction without ensuring agentId is a string. If agentId is an ObjectId, this could lead to unexpected behavior in the visited set tracking.


await processAgent(id, null, type);
// Start processing from the given agent
await processAgent(id, [], type, key === "flow" ? "both" : "down");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an inconsistency in direction naming. The function sets direction to 'both' when key is 'flow', but later checks for direction !== 'down-only'. Consider using consistent direction naming throughout the code.

}

async function getAllConnectedAgents(id, org_id, type) {
async function getAllConnectedAgents(id, org_id, type, key = "orchestral") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider defining constants for the mode values ('orchestral' and 'flow') to prevent typos and ensure consistency throughout the codebase.

Suggested change
async function getAllConnectedAgents(id, org_id, type, key = "orchestral") {
const AGENT_TRAVERSAL_MODES = {
ORCHESTRAL: 'orchestral',
FLOW: 'flow'
};
async function getAllConnectedAgents(id, org_id, type, key = AGENT_TRAVERSAL_MODES.ORCHESTRAL) {

}

// For "flow" key, also traverse parent agents
if (key === "flow" && direction !== "down-only") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why down-only???

}

async function getAllConnectedAgents(id, org_id, type) {
async function getAllConnectedAgents(id, org_id, type, key = "orchestral") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flow and orchestral ko enum banao

const bridgeParents = await configurationModel
.find({
org_id,
$or: [{ [`connected_agents.${agentId}`]: { $exists: true } }, { "connected_agents": { $elemMatch: { $or: [{ version_id: agentId }, { bridge_id: agentId }] } } }]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connected_agents.${agentId}]: { $exists: true } kyu hai yaha agent name hota h .

const versionParents = await bridgeVersionModel
.find({
org_id,
$or: [{ [`connected_agents.${agentId}`]: { $exists: true } }, { "connected_agents": { $elemMatch: { $or: [{ version_id: agentId }, { bridge_id: agentId }] } } }]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connected_agents.${agentId}]: { $exists: true } kyu hai yaha agent name hota h .

- Add AGENT_TRAVERSAL_MODES constant (orchestral, flow) instead of hardcoded strings
- Add TRAVERSAL_DIRECTIONS constant (both, children-only, parents-only)
- Add try/catch error handling to findParentAgents MongoDB queries
- Fix connected_agents query - was using agentId as key but keys are agent names
  Now queries for documents with non-empty connected_agents and filters by
  version_id/bridge_id in JavaScript
- Convert agentId to string in visitKey for proper ObjectId handling
- Use consistent direction naming throughout (children-only instead of down-only)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants