feat: add 'key' parameter to getConnectedAgents API for orchestral/flow modes#856
feat: add 'key' parameter to getConnectedAgents API for orchestral/flow modes#856Husainbw786 wants to merge 2 commits intotestingfrom
Conversation
…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
There was a problem hiding this comment.
Other comments (1)
- src/db_services/agentVersion.service.js (503-543) The findParentAgents function uses complex MongoDB queries but lacks error handling. Consider adding try/catch blocks to handle potential database errors gracefully.
💡 To request another review, post a new comment with "/windsurf-review".
| } | ||
|
|
||
| async function processAgent(agentId, parentIds = [], docType = null, direction = "down") { | ||
| const visitKey = `${agentId}-${direction}`; |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
Consider defining constants for the mode values ('orchestral' and 'flow') to prevent typos and ensure consistency throughout the codebase.
| 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") { |
| } | ||
|
|
||
| async function getAllConnectedAgents(id, org_id, type) { | ||
| async function getAllConnectedAgents(id, org_id, type, key = "orchestral") { |
There was a problem hiding this comment.
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 }] } } }] |
There was a problem hiding this comment.
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 }] } } }] |
There was a problem hiding this comment.
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)
What changed
Added a new
keyquery parameter to thegetConnectedAgentsAPI endpoint (GET /connected-agents/:version_id).New Parameter
orchestral(default) orflowBehavior
Why
The existing API only returned the flow of child agents. This update ensures no connected agent is missed by:
orchestralmodeflowmode that traverses both parent and child relationshipsFiles Changed
src/controllers/agentVersion.controller.js: Addedkeyparameter extraction from querysrc/db_services/agentVersion.service.js: UpdatedgetAllConnectedAgentswith bidirectional traversal logicsrc/validation/joi_validation/bridgeVersion.validation.js: Addedkeyparameter validationAPI Usage