Skip to main content
One of the most powerful features of the Agent Stack is the ability to request structured data from users through interactive forms. Instead of relying on free-form text input, your agent can present users with specific fields, dropdowns, and other form elements to gather precise information. The Agent Stack provides a Form extensions that allows you to collect structured data from users in two ways:
  1. Initial form rendering - Present a form as the first interaction before users start a conversation with your agent
  2. Dynamic form requests - Request forms at any point during a multi-turn conversation when your agent needs specific structured input

Initial Form Rendering

For initial form rendering, you specify the form structure when injecting the extension and then parse the response using a Pydantic model. The form is presented to users before they start a conversation with your agent.
1

Import the form extension

Import FormServiceExtensionServer, FormServiceExtensionSpec, FormRender, and field types from the Agent Stack SDK.
2

Define your form data model

Create a Pydantic model with fields matching your form field IDs.
3

Add form parameter to your agent

Inject the form extension into your agent function using FormServiceExtensionSpec.demand(initial_form=FormRender(...)).
4

Parse form data

Call form.parse_initial_form(model=YourModel) to extract the submitted form data.

Dynamic Form Requests

For dynamic form requests during conversation, you can request forms at any point when your agent needs structured input. This is useful when your agent needs to collect additional information based on the conversation flow.
1

Import the request form extension

Import FormRequestExtensionServer, FormRequestExtensionSpec, FormRender, and field types from the Agent Stack SDK.
2

Define your form data model

Create a Pydantic model with fields matching your form field IDs.
3

Add request form parameter to your agent

Inject the request form extension into your agent function using FormRequestExtensionSpec().
4

Request form dynamically

Call await form_request.request_form(form=FormRender(...), model=YourModel) when you need to collect structured input.

How to work with forms

Here’s what you need to know to add form capabilities to your agent: Import the form components:
  • For form fields and FormRender, import from agentstack_sdk.a2a.extensions
  • For initial forms, import FormServiceExtensionServer and FormServiceExtensionSpec from agentstack_sdk.a2a.extensions
  • For dynamic forms, import FormRequestExtensionServer and FormRequestExtensionSpec from agentstack_sdk.a2a.extensions
Inject the extension: Add a form parameter to your agent function using the Annotated type hint. For initial forms: Use FormServiceExtensionSpec.demand(initial_form=FormRender(...)) to specify the form structure and call form.parse_initial_form(model=YourModel) to extract data. For dynamic forms: Use FormRequestExtensionSpec() and call await form_request.request_form(form=FormRender(...), model=YourModel) when needed. Access form data: The recommended approach is to use a Pydantic model (or TypedDict, dataclass, or any class supported by pydantic.TypeAdapter) to load form data. Define a model with fields matching your form field IDs:
Then, pass model=ContactInfo to parse_initial_form(...) or request_form(...) to get the form data directly as an instance of ContactInfo:
If you don’t use a model, the methods return FormResponse which has a values dictionary. You can access values using form_data.values['field_id'].value. Different field types return different value types:

Form Field Types

The Agent Stack supports various field types for collecting different kinds of structured data:

TextField

Basic text input fields for collecting strings, names, descriptions, etc.

DateField

Date input fields for collecting dates and timestamps.

FileField

File upload fields for collecting files from users.

SingleSelectField

Single-select dropdown fields for choosing single option from a list.

MultiSelectField

Multi-select dropdown fields for choosing multiple options from a list.

CheckboxField

Single checkbox fields for boolean values.

Form Layout Configuration

Control how your form appears using the FormRender configuration:
FormRender properties:
Use col_span on individual fields to control how they span across the grid. For example, with columns=2, a field with col_span=2 will take the full width, while col_span=1 will take half the width.

Examples

For more examples, see: