Skip to content

Using the Emitter

The agentschema-emitter package generates runtime libraries for multiple languages from the AgentSchema TypeSpec definitions. You can use it via CLI or programmatically.

Terminal window
npm install agentschema-emitter

Or use it directly with npx:

Terminal window
npx agentschema-emitter --help

The emitter provides a CLI command agentschema-generate for generating runtime code:

Terminal window
# Generate all default targets (Python, C#, TypeScript, Go)
npx agentschema-generate -o ./generated
# Generate specific targets only
npx agentschema-generate -o ./lib -t python,csharp
# Generate with a different root object
npx agentschema-generate -o ./lib -r AgentSchema.AgentDefinition
# Exclude specific models from generation
npx agentschema-generate -o ./lib --omit AgentManifest,ContainerAgent
OptionShortDescriptionDefault
--output <dir>-oOutput directoryRequired
--targets <list>-tComma-separated targetspython,csharp,typescript,go
--root-object <name>-rRoot model to generateAgentSchema.AgentManifest
--omit <list>Models to excludeNone
--namespace <name>-nOverride namespaceFrom TypeSpec
--no-testsSkip test generationfalse
--no-formatSkip code formattersfalse

You can also use the emitter programmatically in your build scripts:

import { generate } from "agentschema-emitter/generate";
const result = await generate({
output: "./generated",
targets: ["python", "csharp", "typescript", "go"],
rootObject: "AgentSchema.AgentManifest",
omit: ["AgentManifest"],
noTests: false,
noFormat: false,
});
console.log(`Generated ${result.filesGenerated} files`);
interface GenerateOptions {
/** Output directory for generated files */
output: string;
/** Target languages to generate */
targets?: ("python" | "csharp" | "typescript" | "go" | "markdown")[];
/** Root TypeSpec model (fully qualified name) */
rootObject?: string;
/** Models to exclude from generation */
omit?: string[];
/** Override the namespace */
namespace?: string;
/** Skip generating tests */
noTests?: boolean;
/** Skip running code formatters */
noFormat?: boolean;
}
TargetLanguageOutputFeatures
pythonPython 3.10+DataclassesYAML/JSON serialization, type hints
csharpC# 12ClassesSystem.Text.Json, nullable annotations
typescriptTypeScriptInterfacesjs-yaml, camelCase properties
goGo 1.22+Structsencoding/json, gopkg.in/yaml.v3
markdownMarkdownDocsReference documentation

You can also use the emitter as a TypeSpec emitter in your tspconfig.yaml:

emit:
- "agentschema-emitter"
options:
"agentschema-emitter":
root-object: "AgentSchema.AgentManifest"
emit-targets:
- type: Python
output-dir: "./python"
- type: CSharp
output-dir: "./csharp"
- type: TypeScript
output-dir: "./typescript"
- type: Go
output-dir: "./go"

Then run:

Terminal window
npx tsp compile .

All generated runtimes include:

  • YAML/JSON Loading: Load agent definitions from files
  • YAML/JSON Saving: Save agent definitions to files
  • Serialization: Convert to/from JSON and YAML strings
  • Validation: Type-safe models with proper typing
  • Round-trip: Load, modify, and save without data loss
from agentschema import AgentDefinition
# Load from file
agent = AgentDefinition.load("agent.yaml")
# Access properties
print(f"Agent: {agent.name}")
print(f"Model: {agent.model}")
# Modify and save
agent.description = "Updated description"
agent.save("agent-modified.yaml")

If you only need a subset of models, use --omit:

Terminal window
# Generate only AgentDefinition (exclude manifest and container types)
npx agentschema-generate -o ./lib --omit AgentManifest,ContainerAgent

By default, the emitter generates the full type graph starting from AgentManifest. To start from a different type:

Terminal window
# Generate from AgentDefinition as root
npx agentschema-generate -o ./lib -r AgentSchema.AgentDefinition

For projects using only one language:

Terminal window
# Python only
npx agentschema-generate -o ./python -t python
# C# only
npx agentschema-generate -o ./csharp -t csharp