---
name: vex-language
description: "Write, port, debug and review Vex .vx programs using Vex syntax, ownership, standard-library contracts and compiler checks. Use for the Vex systems programming language; VexHDL hardware design has separate documentation."
metadata:
  documentation-target: "0.4.0"
  source: https://vex-lang.org/docs/guide/agent-workflow.md
---

# Vex agent workflow

Use this workflow when writing, porting, debugging or reviewing Vex `.vx` code.
Vex is a separate systems language. Start from its documented syntax and APIs
even when the task resembles Rust, Go, C++ or TypeScript.

## Establish the project

Read the project's instructions, `vex.json` and nearby working code. Check
`vex --version` before choosing commands or interpreting diagnostics. Keep the
user's requested target and dependency constraints. The documentation targets
0.4.0; recorded example checks identify their actual compiler separately in
[verification evidence](references/guide--verification-evidence.md).

For a new project, follow [the first-project walkthrough](references/guide--first-project.md).
For an existing project, reuse its layout and test entry points. Finish this
step with an identified entry file, compiler version and relevant test command.

## Read for the task

Read only the references needed for the change. Start with the corresponding
row, then follow a package link for its exact imports, signatures and ownership.

| Task | Read |
| --- | --- |
| Write or translate a function | [Syntax](references/guide--basics--syntax.md), [variables](references/guide--basics--variables.md), [functions](references/guide--basics--functions.md) |
| Work with records or variants | [Structs](references/guide--types--structs.md), [enums](references/guide--types--enums.md), [error handling](references/guide--error-handling.md) |
| Return, retain or mutate data | [Ownership workflows](references/guide--memory--ownership-workflows.md) |
| Choose a package or parse input | [Standard-library entry path](references/guide--stdlib-start.md), [package map](references/std--index.md), then the selected API guide |
| Validate JSON configuration | [Checked fields and a complete tested program](references/std--serde--json.md) |
| Add a regression or benchmark | [Testing](references/std--testing.md) and the project's existing tests |
| Coordinate async work | [Concurrency overview](https://vex-lang.org/docs/guide/concurrency/overview.md), then the relevant channel/task recipe |
| Call a native library | [First native integration](https://vex-lang.org/docs/guide/ffi-first-native.md) |
| Generate declarations | [Comptime recipes](https://vex-lang.org/docs/guide/advanced/comptime-recipes.md) |
| Use tensors, graphs or devices | [Capability map](https://vex-lang.org/docs/guide/language-status.md), then the specific execution guide |

## Use Vex contracts

- Bind with `let`; use `let!` when rebinding or mutation is required. Read the
  receiver signature before choosing a shared or mutable borrow.
- Use `fn name(...): ReturnType` and the documented `import { Name } from
  "module";` form. Prelude types such as `Vec`, `Map`, `Option` and `Result`
  need no invented package import. Package names such as `"fs"` and
  `"serde/json"` come from their guides.
- Use `$println` and `$format` for builtin formatting. Builtin namespaces
  `Math`, `Bit` and `Crypto` are distinct from imported packages.
- Distinguish owning `string` from borrowed `str`. Keep owners alive while
  retaining views, spans or pointers; use the package's owning conversion when
  data must outlive its input. Follow [ownership workflows](references/guide--memory--ownership-workflows.md)
  for return values, collections, callbacks and async boundaries.
- Preserve `Option` absence and `Result` errors. Use `?` only where the
  enclosing return type supports propagation. Select the actual return type
  from the reference instead of adding `.unwrap()` by analogy.
- For external data, select a checked parser with explicit resource limits
  where available. Wire-format validation and application-schema validation
  are separate steps. The [serde guide](references/std--serde--index.md) describes the dynamic
  parse and field/type/range checks used at input boundaries.

Before using an unfamiliar API, locate its declaration or current reference.
If the installed version differs, preserve the diagnostic and resolve that
specific mismatch against its source or versioned documentation.

## Make the change verifiable

Use the smallest complete program or existing test that exercises the desired
behavior. Keep imports, setup and expected output with the example. Distinguish
copyable programs from fragments that depend on surrounding bindings.

Run the relevant check, program or test with the identified compiler. For
parsers, include a malformed input; for an owning/borrowed conversion, exercise
the intended lifetime; for concurrency, check completion and shutdown. Choose
checks that establish the requested behavior rather than reproducing the
implementation line by line.

When execution is unavailable, report what was source-checked and what remains
unexecuted. Passing a CPU example does not qualify a GPU path, a parser example
does not qualify a protocol session, and successful compilation does not prove
native-library interoperability. Report the files changed, the command and
observed result, and any remaining task-relevant limitation.
