feat: Introduce ManagedAgent and AgentRunner implementations#110
feat: Introduce ManagedAgent and AgentRunner implementations#110jsonbailey wants to merge 6 commits intomainfrom
Conversation
c3f2da2 to
bc8b945
Compare
packages/ai-providers/server-ai-langchain/src/ldai_langchain/langchain_runner_factory.py
Outdated
Show resolved
Hide resolved
packages/ai-providers/server-ai-langchain/src/ldai_langchain/langchain_agent_runner.py
Outdated
Show resolved
Hide resolved
packages/ai-providers/server-ai-langchain/src/ldai_langchain/langchain_agent_runner.py
Outdated
Show resolved
Hide resolved
keelerm84
left a comment
There was a problem hiding this comment.
Looks like bugbot has some good feedback on this one.
packages/ai-providers/server-ai-langchain/src/ldai_langchain/langchain_agent_runner.py
Outdated
Show resolved
Hide resolved
886e3b7 to
a183f12
Compare
feat: Add OpenAIAgentRunner with agentic tool-calling loop feat: Add LangChainAgentRunner with agentic tool-calling loop feat: Add OpenAIRunnerFactory.create_agent(config, tools) -> OpenAIAgentRunner feat: Add LangChainRunnerFactory.create_agent(config, tools) -> LangChainAgentRunner feat: Add ManagedAgent wrapper holding AgentRunner and LDAIConfigTracker feat: Add LDAIClient.create_agent() returning ManagedAgent
…ider helper tests feat: add TestGetAIUsageFromResponse and TestGetToolCallsFromResponse test coverage for LangChainHelper feat: add TestGetAIUsageFromResponse test coverage for OpenAIHelper fix: update ManagedAgent.invoke to use track_metrics_of_async
bc8b945 to
c1b87a6
Compare
packages/ai-providers/server-ai-langchain/src/ldai_langchain/langchain_runner_factory.py
Outdated
Show resolved
Hide resolved
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
packages/ai-providers/server-ai-openai/src/ldai_openai/openai_runner_factory.py
Outdated
Show resolved
Hide resolved
| continue | ||
| if "type" in td: | ||
| # Already in OpenAI format | ||
| tools.append(td) |
There was a problem hiding this comment.
OpenAI runner passes unsupported tool types to API
Medium Severity
_build_openai_tools blindly passes through any tool definition that has a type key, including non-function built-in types like code_interpreter. The Chat Completions API only supports type: 'function', so a single unsupported tool type in the config causes the entire agent run to fail with an API error. The LangChain resolver _resolve_tools_for_langchain correctly filters and warns about non-function types, but the OpenAI runner lacks equivalent logic.
Additional Locations (1)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
There are 4 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| continue | ||
| if "type" in td: | ||
| # Already in OpenAI format | ||
| tools.append(td) |
There was a problem hiding this comment.
Tool format check mishandles LD definitions with type field
High Severity
_build_openai_tools checks if "type" in td and assumes the definition is already in OpenAI format, passing it through unchanged. However, LD tool definitions can include a type field (e.g., {'type': 'function', 'name': 'get-weather', ...}), which the LangChain helper explicitly handles. When such a definition is encountered, it gets passed to OpenAI in the flat LD format instead of the required nested format ({'type': 'function', 'function': {'name': ..., ...}}), causing the API call to fail.
| "role": "tool", | ||
| "tool_call_id": tool_call.id, | ||
| "content": result, | ||
| }) |
There was a problem hiding this comment.
Agent loop lacks maximum iteration guard
Medium Severity
The while True agentic loop in OpenAIAgentRunner.run has no maximum iteration limit. If the model keeps returning tool calls (e.g., due to a misconfigured tool that always triggers re-invocation, or a model that loops on unavailable tools), this runs indefinitely — burning API tokens and potentially hanging the process. The LangChain equivalent delegates to lc_create_agent, which has a built-in recursion limit. A similar safeguard is missing here.
| description=td.get('description', ''), | ||
| )) | ||
|
|
||
| return structured |
There was a problem hiding this comment.
Duplicated tool-filtering logic in two functions
Low Severity
build_structured_tools and _resolve_tools_for_langchain contain nearly identical tool-filtering logic: checking isinstance(td, dict), checking the type field, extracting name, verifying registry membership, and logging the same warnings. The only difference is the output format (dicts vs StructuredTool). Extracting the shared filtering into a common helper would reduce duplication and the risk of inconsistent updates.


feat: Add OpenAIAgentRunner with agentic tool-calling loop
feat: Add LangChainAgentRunner with agentic tool-calling loop
feat: Add OpenAIRunnerFactory.create_agent(config, tools) -> OpenAIAgentRunner
feat: Add LangChainRunnerFactory.create_agent(config, tools) -> LangChainAgentRunner
feat: Add ManagedAgent wrapper holding AgentRunner and LDAIConfigTracker
feat: Add LDAIClient.create_agent() returning ManagedAgent
Requirements
Related issues
Provide links to any issues in this repository or elsewhere relating to this pull request.
Describe the solution you've provided
Provide a clear and concise description of what you expect to happen.
Describe alternatives you've considered
Provide a clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context about the pull request here.
Note
Medium Risk
Introduces new agent execution path (including OpenAI tool-calling loop) and a new
LDAIClient.create_agentAPI, which could affect runtime behavior and metrics/usage tracking for agent configs. Risk is moderated by added unit tests, but tool execution/looping adds complexity and potential edge cases.Overview
Adds first-class managed agent invocation to the server AI SDK via
ManagedAgentandLDAIClient.create_agent(), including event tracking for agent creation.Implements provider-side agent runners for OpenAI (
OpenAIAgentRunner) and LangChain (LangChainAgentRunner) pluscreate_agent()factory methods; OpenAI runs an explicit tool-calling loop and aggregates token usage across turns, while LangChain delegates to a compiled agent graph.Extends tool support and usage handling: LangChain can now bind/construct tools from config +
ToolRegistry, and both OpenAI/LangChain usage extractors now returnNonewhen all token counts are zero. Test suites are expanded to cover agent creation/execution, tool-call parsing, and usage edge cases.Written by Cursor Bugbot for commit e4b3830. This will update automatically on new commits. Configure here.