Guides

Python SDK: create & train agents

Build packs, run evaluations, tune routing, export datasets.

Python is the builder's language in the LyboAI ecosystem. Agents run in the Rust runtime (desktop binary or on-device); the lyboai package drives that runtime over the same protocol the mobile bindings use, and adds the authoring/training loop around it.

  1. 1

    Install and connect

    pip install -e sdk/python
    cargo build -p lybo-cli
  2. 2

    Create an agent in a few lines

    from lyboai import Client
    
    with Client(data_dir="/tmp/agent") as lybo:
        lybo.install_knowledge(doc_id="h", title="Handbook",
            body="Tickets are answered within 24 hours.")
        lybo.register_skill(skill_id="app.ask", name="Ask",
            triggers=["what does the handbook say"],
            keywords=["handbook"], pattern="retrieval")
        s = lybo.start_session()
        print(lybo.run_to_completion(s, "what does the handbook say?"))
  3. 3

    Train routing from labelled examples

    Class-discriminative tf-idf picks keywords that separate your skills; the phrases also build the on-device semantic centroids.

    from lyboai import train_triggers
    learned = train_triggers({
      "faq.ask": ["what does the guide say about refunds", "search the faq"],
      "task.plan": ["plan my week", "break this goal into steps"],
    })
  4. 4

    Build → sign → evaluate → gate CI

    from lyboai import PackBuilder, sign_pack, evaluate
    
    PackBuilder("acme.faq", "FAQ", "1.0.0", "acme") \
      .add_knowledge("faq", "Store FAQ", "Refunds take five days.") \
      .add_skill("faq.ask", "Ask FAQ", pattern="retrieval",
                 triggers=learned["faq.ask"]["triggers"],
                 keywords=learned["faq.ask"]["keywords"]) \
      .add_eval_case("s", "routes", "what does the guide say about refunds",
                     expect_skill="faq.ask", expect_contains=["refund"]) \
      .save("pack.json")
    sign_pack("pack.json", SECRET, "dist/faq.lybopack")
    # install into a throwaway runtime and assert report.ok in CI
  5. 5

    Export privacy-safe training data

    Routing/outcome metadata from traces (never raw user content) — the input to tiny-classifier distillation pipelines.

    from lyboai import export_routing_dataset
    export_routing_dataset(lybo, "routing.jsonl")
The starter template (templates/starter-agent) is this whole loop in one runnable script — see *Starter agent (ready to go)*.