Repository navigation
Replies: 1 comment
|
There are two separate issues in the Loki example: the tool’s parameter schema and the Loki endpoint. With Use a single parameter model: import httpx
from copilot.tools import define_tool
from pydantic import BaseModel, Field
class LokiParams(BaseModel):
query: str = Field(
min_length=1,
description="LogQL log query using actual Loki labels",
)
limit: int = Field(default=50, ge=1, le=1000)
@define_tool(
description="Fetch recent Loki log lines using a LogQL log query."
)
async def query_loki(params: LokiParams) -> dict:
async with httpx.AsyncClient(timeout=5.0) as client:
response = await client.get(
"http://localhost:3100/loki/api/v1/query_range",
params={"query": params.query, "limit": params.limit},
)
response.raise_for_status()
data = response.json()["data"]
if data["resultType"] != "streams":
raise ValueError(
"Expected a LogQL log query, not a metric query."
)
logs = [
value[1]
for stream in data["result"]
for value in stream["values"]
]
return {
"query": params.query,
"log_count": len(logs),
"logs": logs,
}Register this updated tool in your session’s This gives the model an explicit schema and rejects missing For log lines, use References: Python SDK tools and Loki HTTP API. Validation: local checks with SDK 1.0.28 and mocked HTTP confirmed schema generation, rejection of missing arguments, successful log extraction, and failure handling for HTTP errors. This was not tested against a live Copilot session or Loki deployment; the original post does not specify its SDK version. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I’m building an SRE-style assistant using GitHub Copilot SDK (Python) with tool calling.
Context
What I’m trying to do
I defined tools using
@define_toolso the AI can:code
Problem
When I ask the AI something like:
"Show me recent error logs from compute nodes"
The tool does get called, but:
so:
What I’ve verified
Questions
All reactions