mirror of
https://github.com/hoshikawa2/agent_platform_oci.git
synced 2026-07-09 14:04:19 +00:00
Ajustes na documentação e remanejamento dos folders
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def get_gateway_model_policy(state: dict[str, Any]) -> dict[str, Any] | None:
|
||||
metadata = state.get("metadata") or {}
|
||||
policy = metadata.get("model_policy")
|
||||
return policy if isinstance(policy, dict) else None
|
||||
|
||||
|
||||
def apply_gateway_model_policy_to_llm_kwargs(
|
||||
state: dict[str, Any],
|
||||
fallback_profile: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
policy = get_gateway_model_policy(state)
|
||||
if not policy:
|
||||
return fallback_profile or {}
|
||||
|
||||
params = dict(policy.get("parameters") or {})
|
||||
if policy.get("model"):
|
||||
params["model"] = policy["model"]
|
||||
if policy.get("provider"):
|
||||
params["provider"] = policy["provider"]
|
||||
if policy.get("profile"):
|
||||
params["profile"] = policy["profile"]
|
||||
return params
|
||||
@@ -0,0 +1,3 @@
|
||||
from .mcp_gateway_client import MCPGatewayClient
|
||||
|
||||
__all__ = ["MCPGatewayClient"]
|
||||
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
|
||||
class MCPGatewayClient:
|
||||
def __init__(self, base_url: str, token: str | None = None, timeout_seconds: int = 60):
|
||||
self.base_url = base_url.rstrip("/")
|
||||
self.token = token
|
||||
self.timeout_seconds = timeout_seconds
|
||||
|
||||
def _headers(self) -> dict[str, str]:
|
||||
return {"Authorization": f"Bearer {self.token}"} if self.token else {}
|
||||
|
||||
async def list_tools(self) -> dict[str, Any]:
|
||||
async with httpx.AsyncClient(timeout=self.timeout_seconds) as client:
|
||||
response = await client.get(f"{self.base_url}/v1/tools", headers=self._headers())
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def invoke_tool(
|
||||
self,
|
||||
*,
|
||||
tenant_id: str,
|
||||
agent_id: str,
|
||||
channel: str | None,
|
||||
tool_name: str,
|
||||
arguments: dict[str, Any] | None = None,
|
||||
business_context: dict[str, Any] | None = None,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
payload = {
|
||||
"tenant_id": tenant_id,
|
||||
"agent_id": agent_id,
|
||||
"channel": channel,
|
||||
"tool_name": tool_name,
|
||||
"arguments": arguments or {},
|
||||
"business_context": business_context or {},
|
||||
"metadata": metadata or {},
|
||||
}
|
||||
async with httpx.AsyncClient(timeout=self.timeout_seconds) as client:
|
||||
response = await client.post(
|
||||
f"{self.base_url}/v1/tools/{tool_name}/invoke",
|
||||
json=payload,
|
||||
headers=self._headers(),
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from agent_framework.gateways import MCPGatewayClient
|
||||
|
||||
|
||||
class MCPGatewayRuntimeMixin:
|
||||
mcp_gateway_client: MCPGatewayClient | None = None
|
||||
|
||||
async def _invoke_mcp_gateway_tool(
|
||||
self,
|
||||
state: dict[str, Any],
|
||||
tool_name: str,
|
||||
arguments: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
if not self.mcp_gateway_client:
|
||||
raise RuntimeError("MCP Gateway client not configured")
|
||||
|
||||
result = await self.mcp_gateway_client.invoke_tool(
|
||||
tenant_id=state.get("tenant_id", "default"),
|
||||
agent_id=state.get("agent_id") or state.get("route") or "unknown",
|
||||
channel=state.get("channel"),
|
||||
tool_name=tool_name,
|
||||
arguments=arguments or {},
|
||||
business_context=state.get("business_context") or {},
|
||||
metadata={
|
||||
"session_id": state.get("session_id"),
|
||||
"conversation_key": state.get("conversation_key"),
|
||||
"trace_id": (state.get("metadata") or {}).get("trace_id"),
|
||||
},
|
||||
)
|
||||
|
||||
state.setdefault("mcp_results", []).append(result)
|
||||
return result
|
||||
Reference in New Issue
Block a user