File size: 1,277 Bytes
95d6832
7f94735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f45521
 
 
 
 
 
 
7f94735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Ask the agent one question, end to end (runs the agent tool loop).

    python scripts/ask.py "how do I build a CNN to classify images?"
    python scripts/ask.py "how is conv2d implemented?"
"""

from __future__ import annotations

import argparse
import sys

from dotenv import load_dotenv


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("question")
    args = parser.parse_args()

    load_dotenv()
    from agent.guard import guard

    verdict = guard(args.question)  # vet the user input once, before the pipeline
    if not verdict.ok:
        print(f"[guard] {verdict.reason}: {verdict.message}")
        return 0

    from agent.loop import answer_agentic

    answer = answer_agentic(args.question)

    print("\n" + "=" * 70)
    print(answer.answer_md)
    if answer.citations:
        print("\nCitations:")
        for c in answer.citations:
            anchor = f"#{c.anchor}" if c.anchor else ""
            print(f"  - {c.title or c.url}{anchor}\n    {c.url}{anchor}")
    if answer.referrals:
        print("\nBeyond these docs, see:")
        for r in answer.referrals:
            print(f"  - {r.url}  ({r.reason})")
    print("=" * 70)
    return 0


if __name__ == "__main__":
    sys.exit(main())