Skip to content

Commit 9be6604

Browse files
committed
added new repo info tool with test
1 parent c5e7a0f commit 9be6604

6 files changed

Lines changed: 670 additions & 49 deletions

File tree

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
OPENAI_API_KEY=sk-xxxx
2+
GITHUB_TOKEN=ghp_xxxx
23
# Optional model overrides (defaults work):
34
OPENAI_MODEL=gpt-4o
45

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,6 @@ runs/
163163
logs/
164164
dataset/
165165
else/
166-
artifacts/
166+
artifacts/
167+
_out/
168+
notes.txt

src/ai_agent/agent/agent.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from api.pipeline import RAGImagingPipeline
1212
from utils.utils import _best_runnable_link
1313
from .models import AgentToolSelection, ToolRunLog
14-
from .tools.repo_info_tool import tool_repo_info, RepoInfoInput
14+
from .tools.repo_info_tool import tool_repo_summary, RepoSummaryInput, coerce_github_url_or_none
1515
from .tools.rerank_tool import tool_rerank, RerankInput
1616
from .tools.search_tool import tool_search_tools, SearchToolsInput
1717
from .tools.gradio_space_tool import tool_run_example, RunExampleInput
@@ -80,12 +80,32 @@ async def rerank(ctx: RunContext[AgentState], query: str, candidate_names: List[
8080
# })
8181
# return out.model_dump(mode="python")
8282

83-
@agent.tool(retries=2, prepare=cap_prepare)
84-
@limit_tool_calls("repo_info", cap=2)
83+
@agent.tool(retries=0, prepare=cap_prepare)
84+
@limit_tool_calls("repo_info", cap=3)
8585
async def repo_info(ctx: RunContext[AgentState], url: str):
86-
out = tool_repo_info(RepoInfoInput(url=url))
87-
ctx.deps.tool_calls.append({"tool": "repo_info", "url": url, "truncated": out.truncated})
88-
return out.model_dump(mode="python")
86+
norm_url = coerce_github_url_or_none(url)
87+
if not norm_url:
88+
payload = {
89+
"invalid": True,
90+
"reason": "NON_GITHUB_URL",
91+
"hint": "Pass a GitHub repo URL or 'owner/repo' to repo_info(url).",
92+
"original": url,
93+
}
94+
ctx.deps.tool_calls.append({"tool": "repo_info", "url": url, "skipped": True, "reason": "NON_GITHUB_URL"})
95+
return payload
96+
97+
try:
98+
out = tool_repo_summary(RepoSummaryInput(url=norm_url))
99+
ctx.deps.tool_calls.append({"tool": "repo_info", "url": norm_url, "truncated": out.truncated})
100+
return out.model_dump(mode="python")
101+
except Exception as e:
102+
ctx.deps.tool_calls.append({"tool": "repo_info", "url": norm_url, "error": str(e)})
103+
return {
104+
"invalid": True,
105+
"reason": "FETCH_FAILED",
106+
"url": norm_url,
107+
"message": str(e),
108+
}
89109

90110
@agent.tool(retries=2, prepare=cap_prepare)
91111
@limit_tool_calls("resolve_demo_link", cap=3)
@@ -126,8 +146,7 @@ def run_agent(task: str, image_data_url: str | None = None, excluded: List[str]
126146
short_meta = " ".join(x.strip() for x in image_meta.splitlines() if x.strip())
127147
hidden_meta += "\n(Image Metadata: " + short_meta[:500] + ("…" if len(short_meta) > 500 else "") + ")"
128148
prompt = task + extra_context + hidden_meta
129-
log.info(f"Agent prompt: {prompt}")
130-
result = agent.run_sync(prompt, deps=deps, output_type=ToolSelection, usage_limits=UsageLimits(tool_calls_limit=6)).output
149+
result = agent.run_sync(prompt, deps=deps, output_type=ToolSelection, usage_limits=UsageLimits(tool_calls_limit=10)).output
131150

132151
# Convert tool call dicts into ToolRunLog entries
133152
for tc in deps.tool_calls:
@@ -153,4 +172,4 @@ def run_agent(task: str, image_data_url: str | None = None, excluded: List[str]
153172
tool_calls=tool_logs,
154173
)
155174

156-
__all__ = ["run_agent", "agent"]
175+
__all__ = ["run_agent", "agent"]

0 commit comments

Comments
 (0)