Examples

Validated examples for the current SDK layout.

These examples match the current sdk-examples/ directory and the current runtime semantics. The commands below were aligned to the repo-level launch scripts and the clean no-key skip paths, so they are useful both as docs and as a practical validation surface.

SDK Examples

What ships in the repo

The SDK examples are intentionally split between no-key examples that always run, and model-backed examples that execute live when provider credentials are present.

Example Command What it covers Credential behavior
No-key SDK demo npx tsx sdk-examples/no-api-key.ts Tool registration, whitelist and blacklist policy behavior, and a Prolog-only DML run with no model call. Runs without provider keys.
Quick start npm run example Minimal SDK setup plus a simple task() and answer() flow. Skips cleanly when GOOGLE_GENERATIVE_AI_API_KEY is missing.
Basic usage set npm run examples Tool policy demo by default, plus numbered examples for custom tools, user input, cancellation, and a research flow. The default launcher works without keys because it falls back to the tool-policy example.
Neurosymbolic examples npx tsx sdk-examples/neurosymbolic.ts 1 Constraint filtering, symbolic reasoning, and backtracking-oriented workflows. Skips cleanly when GOOGLE_GENERATIVE_AI_API_KEY is missing.
Deep research agent npx tsx sdk-examples/deep-research.ts "test topic" Interactive research flow, Brave-backed search, report generation, and follow-up questions. Skips cleanly without Google credentials and falls back to mock search when Brave credentials are absent.
Notes

How to choose the right example

Start here

sdk-examples/no-api-key.ts is the fastest way to confirm the SDK, runtime, and local tool wiring are functioning at all.

First live model call

sdk-examples/quick-start.ts is the smallest model-backed example once GOOGLE_GENERATIVE_AI_API_KEY is configured.

API patterns

sdk-examples/basic-usage.ts is the broadest reference for tool registration, policies, positional agent_main args, and event handling.

Flagship workflow

sdk-examples/deep-research.ts is the best example when you want a longer-running orchestration flow instead of a minimal SDK snippet.

Smoke Test

One command for the current no-key environment

The repo now includes a smoke command that exercises the no-key example, the quick-start launcher, the default basic-usage launcher, and the clean skip paths for the key-backed examples.

npm run examples:smoke
  • Runs sdk-examples/no-api-key.ts fully.
  • Checks the repo-level npm run example and npm run examples scripts.
  • Confirms the clean no-key skip behavior for neurosymbolic.ts and deep-research.ts.
  • Exits 0 in a repo that has no provider keys configured.
Live provider runs To execute the model-backed flows for real, set GOOGLE_GENERATIVE_AI_API_KEY. To enable real Brave-backed search in deep-research.ts, also set BRAVE_API_KEY or BRAVE_KEY.