File size: 4,019 Bytes
309879b dec214e 79cb264 db05121 309879b db05121 309879b db05121 309879b 79cb264 db05121 00537c6 db05121 00537c6 71a6e4c 00537c6 71a6e4c db05121 00537c6 db05121 00537c6 db05121 00537c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | ---
title: AKD - Code Search Agent
emoji: π»
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
short_description: Agent that discovers public scientific code repositories.
---
# π» Code Search Agent
A chat demo of the **CARE v2 Scientific Code Discovery Agent**. Describe a
scientific task and the agent discovers relevant **public code repositories**
(NASA-verified repo search, the Science Discovery Engine, optional ASCL/ADS
citation evidence, and the web), then returns a ranked, evidence-backed
comparison. Each answer keeps a visible **agent-activity** timeline and a
collapsible **reasoning trace**, and you can keep chatting to refine the results.
**Artifacts-driven:** the agent's instructions are NOT hardcoded. They are loaded
at startup from the agent's CARE workspace artifacts bundled in `./artifact` β a
copy of [NASA-IMPACT/akd-plugins](https://github.com/NASA-IMPACT/akd-plugins)
β `plugins/code-search-assistant` (the skill's `SKILL.md` is bundled as
`agents.md`; `references/` β per-domain contexts, guardrails, tool specs, output
spec β ride along and are exposed to the agent through a `read_reference` tool).
**Runtime:** pydantic-ai (OpenAI Responses API) + the plugin's hosted FastMCP
discovery servers + OpenAI hosted web search. **Bring your own OpenAI key** β
entered in the UI, used only for your session, never stored. The Space owner
supplies the MCP tokens (secrets).
**Guardrailed (pydantic-ai v2 harness):** every turn is checked by the
[NASA-IMPACT/akd-guardrails](https://github.com/NASA-IMPACT/akd-guardrails)
service, attached as `InputGuard` / `OutputGuard` capabilities on the agent β
`gliguard` (GLiNER) screens each user prompt *before the model is invoked*
(hard block, zero tokens), and `risk_agent` (LLM judge) reviews the final
answer (with the run's tool returns as grounding context) before it renders.
No guard logic lives in this app; it only relays verdicts. Blocked turns show
`β Blocked by AKD input/output guardrails: <risks>`, and blocked answers never
enter the conversation memory. If the guardrails service itself is unreachable,
checks fail open (logged).
## Run locally
```bash
cd code-search-agent
pip install -r requirements.txt
# .env (not committed): CODE_SEARCH_MCP_KEY=β¦ (+ optional vars below)
python app.py
```
## Deploy (private Docker Space)
See [DEPLOY.md](DEPLOY.md) for the full walkthrough. In short:
1. Create a **private** Space with **SDK: Docker**.
2. Set runtime secrets in **Settings β Secrets** (no build secrets needed β
all dependencies are public):
- `CODE_SEARCH_MCP_KEY` β FastMCP token for the primary discovery server.
- optional: `CODE_SIGNALS_MCP_KEY`, `ADS_ASCL_MCP_KEY`.
3. Push `Dockerfile`, `app.py`, `requirements.txt`, `bot-avatar-v2.png`,
`artifact/`, and this `README.md` to the Space.
The OpenAI key is supplied by each visitor at runtime (bring-your-own-key).
## Configuration (runtime env vars / Space secrets)
| Variable | Required | Purpose |
| --- | --- | --- |
| `CODE_SEARCH_MCP_KEY` | yes | Token for the primary discovery server (`repository_search_tool`, `sde_search_tool`). |
| `CODE_SEARCH_MCP_URL` | no | Override the primary server URL (default: the plugin's `sde-repo-search` server). |
| `CODE_SIGNALS_MCP_KEY` | no | Token for the code-signals server (static code inspection channel). |
| `CODE_SIGNALS_MCP_URL` | no | Override the code-signals server URL. |
| `ADS_ASCL_MCP_KEY` | no | Token for the ASCL/ADS server (Astrophysics citation channel). |
| `ADS_ASCL_MCP_URL` | no | Override the ASCL/ADS server URL. |
| `AKD_GUARDRAILS_URL` | no | AKD guardrails service base URL (default: the dev ALB). |
| `ARTIFACT_DIR` | no | Artifact folder override (default `./artifact`). |
| `AGENT_MODEL` | no | Default model id (default `gpt-5.2`). |
Servers are probed once at startup: a channel whose token is missing or rejected
is dropped and disclosed to the agent, which notes it in **Search Notes** instead
of fabricating results.
|