Meteord commited on
Commit
b7097af
·
verified ·
1 Parent(s): 218632a

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. app/ckan_agent.py +16 -0
app/ckan_agent.py CHANGED
@@ -229,6 +229,8 @@ def validate_action(action: AgentAction, session: AgentSession) -> tuple[AgentAc
229
  package_id = str(action.args.get("package_id", "")).strip()
230
  if package_id not in session.packages:
231
  return action, f"package_show package_id was not observed: {package_id}"
 
 
232
  if action.action == "select_resource":
233
  resource_id = str(action.args.get("resource_id", "")).strip()
234
  if resource_id not in session.resources:
@@ -247,6 +249,18 @@ def fallback_action(session: AgentSession) -> AgentAction:
247
  for package_id, package in session.packages.items():
248
  if package_id and not package.get("_shown"):
249
  return AgentAction("package_show", {"package_id": package_id}, "Inspect the next observed package.", 0.45, "fallback")
 
 
 
 
 
 
 
 
 
 
 
 
250
  if "tag_search" not in session.catalog_tools_run:
251
  query = _catalog_query(session.prompt)
252
  return AgentAction("tag_search", {"query": query, "rows": 10}, "Discover matching CKAN tags before package search.", 0.45, "fallback")
@@ -539,6 +553,8 @@ def _score_resource(resource: RetrievalResource, prompt: str) -> float:
539
  score += 0.45
540
  if any(term in haystack for term in terms):
541
  score += 0.25
 
 
542
  if "metadata" in haystack or "metadaten" in haystack:
543
  score -= 0.2
544
  return max(0.0, min(score, 1.0))
 
229
  package_id = str(action.args.get("package_id", "")).strip()
230
  if package_id not in session.packages:
231
  return action, f"package_show package_id was not observed: {package_id}"
232
+ if session.packages[package_id].get("_shown"):
233
+ return action, f"package_show package_id was already inspected: {package_id}"
234
  if action.action == "select_resource":
235
  resource_id = str(action.args.get("resource_id", "")).strip()
236
  if resource_id not in session.resources:
 
249
  for package_id, package in session.packages.items():
250
  if package_id and not package.get("_shown"):
251
  return AgentAction("package_show", {"package_id": package_id}, "Inspect the next observed package.", 0.45, "fallback")
252
+ best_resource = _best_observed_resource(session)
253
+ if best_resource:
254
+ return AgentAction(
255
+ "select_resource",
256
+ {
257
+ "resource_id": best_resource.resource_id,
258
+ "match_evidence": f"Observed resource '{best_resource.name}' belongs to matching package '{best_resource.package_title}'.",
259
+ },
260
+ "Select the best observed resource instead of repeating inspection.",
261
+ max(MIN_SELECTION_CONFIDENCE, _score_resource(best_resource, session.prompt)),
262
+ "fallback",
263
+ )
264
  if "tag_search" not in session.catalog_tools_run:
265
  query = _catalog_query(session.prompt)
266
  return AgentAction("tag_search", {"query": query, "rows": 10}, "Discover matching CKAN tags before package search.", 0.45, "fallback")
 
553
  score += 0.45
554
  if any(term in haystack for term in terms):
555
  score += 0.25
556
+ if any(term in haystack for term in ("fahrrad", "rad", "raddauer", "radverkehr")) and any(term in prompt.casefold() for term in ("fahrrad", "fahrräder", "rad", "bike", "bicycle")):
557
+ score += 0.25
558
  if "metadata" in haystack or "metadaten" in haystack:
559
  score -= 0.2
560
  return max(0.0, min(score, 1.0))