File size: 2,392 Bytes
06793fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""CLI wrapper for AgentMemory lesson operations."""

import sys
import argparse
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from memory import AgentMemory


def main():
    parser = argparse.ArgumentParser(description="Manage agent lessons learned")
    parser.add_argument("--db", help="Database path", default=None)
    subparsers = parser.add_subparsers(dest="command", required=True)
    
    # add command
    add_p = subparsers.add_parser("add", help="Record a lesson learned")
    add_p.add_argument("action", help="What was done")
    add_p.add_argument("context", help="Situation/topic")
    add_p.add_argument("outcome", choices=["positive", "negative", "neutral"], help="Result")
    add_p.add_argument("insight", help="What was learned")
    
    # list command
    list_p = subparsers.add_parser("list", help="List lessons")
    list_p.add_argument("--context", "-c", help="Filter by context")
    list_p.add_argument("--outcome", "-o", choices=["positive", "negative", "neutral"])
    list_p.add_argument("--limit", "-n", type=int, default=20)
    
    # apply command
    apply_p = subparsers.add_parser("apply", help="Mark a lesson as applied")
    apply_p.add_argument("lesson_id", help="ID of lesson to mark applied")
    
    args = parser.parse_args()
    mem = AgentMemory(db_path=args.db)
    
    if args.command == "add":
        lesson_id = mem.learn(
            action=args.action,
            context=args.context,
            outcome=args.outcome,
            insight=args.insight
        )
        emoji = {"positive": "โœ…", "negative": "โŒ", "neutral": "โž–"}[args.outcome]
        print(f"{emoji} Lesson [{lesson_id}]: {args.insight[:60]}...")
        
    elif args.command == "list":
        lessons = mem.get_lessons(context=args.context, outcome=args.outcome, limit=args.limit)
        if not lessons:
            print("No lessons found.")
        for l in lessons:
            emoji = {"positive": "โœ…", "negative": "โŒ", "neutral": "โž–"}[l.outcome]
            print(f"{emoji} [{l.id}] {l.context}: {l.insight}")
            print(f"   Action: {l.action} | Applied: {l.applied_count}x")
            
    elif args.command == "apply":
        mem.apply_lesson(args.lesson_id)
        print(f"๐Ÿ“ Marked lesson {args.lesson_id} as applied")


if __name__ == "__main__":
    main()