Skip to content

Conversation

@luv-bansal
Copy link
Contributor

@luv-bansal luv-bansal commented Dec 5, 2025

Pull request overview

This PR introduces a new AgenticModelClass that extends OpenAIModelClass to enable agentic behavior by integrating LLMs with MCP (Model Context Protocol) servers. The class provides tool discovery, execution, and iterative tool calling capabilities for both chat completions and responses endpoints, supporting both streaming and non-streaming modes.

LLM with MCP servers client example

from openai import OpenAI
import os
client = OpenAI(
    base_url="https://api.clarifai.com/v2/ext/openai/v1",
    api_key= os.environ['CLARIFAI_PAT']
)
mcp_servers = [
    "https://api.clarifai.com/v2/ext/mcp/v1/users/clarifai/apps/mcp/models/calculator-mcp-server",
    "https://api.clarifai.com/v2/ext/mcp/v1/users/clarifai/apps/mcp/models/web-search-mcp-server",
]
completion = client.chat.completions.create(
    model="https://clarifai.com/clarifai/agentic-model/models/gpt-5_1",
    messages=[{"role": "user", "content": "What's the weather in Los Angeles, California?"}],
    extra_body={"mcp_servers": mcp_servers},
    max_completion_tokens=10000,
    stream=True
)
for chunk in completion:
    if chunk.choices and len(chunk.choices) > 0 and hasattr(chunk.choices[0].delta, 'content') and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
    elif chunk.choices and len(chunk.choices) > 0 and hasattr(chunk.choices[0].delta, 'reasoning_content') and chunk.choices[0].delta.reasoning_content:
        print(chunk.choices[0].delta.reasoning_content, end="", flush=True)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new AgenticModelClass that extends OpenAIModelClass to enable agentic behavior by integrating LLMs with MCP (Model Context Protocol) servers. The class provides tool discovery, execution, and iterative tool calling capabilities for both chat completions and responses endpoints, supporting both streaming and non-streaming modes.

Key Changes

  • Adds MCP server connection and tool discovery with retry logic and resource cleanup
  • Implements token usage accumulation across multiple API calls in agentic flows
  • Provides streaming and non-streaming support for iterative tool execution with both chat completions and responses API endpoints

@luv-bansal luv-bansal changed the title Agentic Class [PR-1090] Agentic Class Dec 5, 2025
@luv-bansal luv-bansal marked this pull request as draft December 5, 2025 13:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 16 comments.

@luv-bansal luv-bansal requested a review from Copilot December 15, 2025 07:31
@luv-bansal luv-bansal marked this pull request as ready for review December 15, 2025 07:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 33 comments.

Copy link
Contributor

Copilot AI commented Dec 15, 2025

@luv-bansal I've opened a new pull request, #875, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 15, 2025

@luv-bansal I've opened a new pull request, #876, to work on those changes. Once the pull request is ready, I'll request review from you.

luv-bansal and others added 5 commits December 15, 2025 14:11
…cycle (#875)

* Initial plan

* Add comprehensive test coverage for MCPConnectionPool

Co-authored-by: luv-bansal <[email protected]>

* Improve test robustness based on code review feedback

Co-authored-by: luv-bansal <[email protected]>

* Optimize test execution time and improve mock specifications

Co-authored-by: luv-bansal <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: luv-bansal <[email protected]>
@luv-bansal luv-bansal requested a review from Copilot December 15, 2025 11:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 15 comments.

@github-actions
Copy link

Code Coverage

Package Line Rate Health
clarifai 45%
clarifai.cli 58%
clarifai.cli.templates 46%
clarifai.client 67%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.modules 0%
clarifai.rag 0%
clarifai.runners 54%
clarifai.runners.models 65%
clarifai.runners.pipeline_steps 41%
clarifai.runners.pipelines 77%
clarifai.runners.utils 62%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 60%
clarifai.utils 60%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 63% (9141 / 14541)

Minimum allowed line rate is 50%

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants