mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-08 04:27:44 +00:00
feat: init pydantic ai agent & context 7 mcp (#1240)
* feat: init pydantic ai agent & context 7 mcp * feat: integrate MCP documentation search into data science pipeline evaluation * fix: disable MCP documentation search and update related docstrings and defaults * lint * fix: correct prompt formatting and conditional blocks in pipeline_eval section * lint * feat: add query method to PAIAgent for synchronous agent execution * fix: apply nest_asyncio for agent and update context7 query method * lint * lint * lint * lint * docs: update MCP folder docstring and rename test class in test_pydantic.py * refactor: centralize completion kwargs logic and update pydantic_ai integration * fixbug * typo * fix: bug triggered by padantic-ai version backtracking. --------- Co-authored-by: Linlang <Lv.Linlang@hotmail.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
import nest_asyncio
|
||||
from pydantic_ai import Agent
|
||||
from pydantic_ai.mcp import MCPServerStreamableHTTP
|
||||
|
||||
from rdagent.oai.backend.pydantic_ai import get_agent_model
|
||||
|
||||
|
||||
class BaseAgent:
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, system_prompt: str, toolsets: list[str]): ...
|
||||
|
||||
@abstractmethod
|
||||
def query(self, query: str) -> str: ...
|
||||
|
||||
|
||||
class PAIAgent(BaseAgent):
|
||||
"""
|
||||
Pydantic-AI agent
|
||||
"""
|
||||
|
||||
agent: Agent
|
||||
|
||||
def __init__(self, system_prompt: str, toolsets: list[str | MCPServerStreamableHTTP]):
|
||||
toolsets = [(ts if isinstance(ts, MCPServerStreamableHTTP) else MCPServerStreamableHTTP(ts)) for ts in toolsets]
|
||||
self.agent = Agent(get_agent_model(), system_prompt=system_prompt, toolsets=toolsets)
|
||||
|
||||
def query(self, query: str) -> str:
|
||||
"""
|
||||
|
||||
Parameters
|
||||
----------
|
||||
query : str
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
"""
|
||||
|
||||
nest_asyncio.apply() # NOTE: very important. Because pydantic-ai uses asyncio!
|
||||
result = self.agent.run_sync(query)
|
||||
return result.output
|
||||
Reference in New Issue
Block a user