-
Notifications
You must be signed in to change notification settings - Fork 137
chore: form extension rework #1481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
439c3ba
chore: form extension rework first iteration
tomkis d566c64
chore: dynammic forms rework
tomkis c97494e
fix: autofixing & imporvements
tomkis 1a99c98
fix: missing headers
tomkis 738dbca
chore: rework CLI after forms rework
tomkis eecbb97
fix: build
tomkis 4790cf3
chore: improving request form agent
tomkis 5699fe6
chore: initial form data improvements
tomkis 666efe2
fix: minor improvements
tomkis 93634a3
fix: update docs for the forms
tomkis 94c0d5b
fix: code review
tomkis df38d8b
fixup! fix: code review
PetrBulanek 2219868
chore: rename request_form to form_request
PetrBulanek 440f722
fixup! chore: rename request_form to form_request
PetrBulanek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Copyright 2025 © BeeAI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from typing import Annotated | ||
|
|
||
| from a2a.types import Message | ||
| from pydantic import BaseModel | ||
|
|
||
| from agentstack_sdk.a2a.extensions.common.form import FormRender, TextField | ||
| from agentstack_sdk.a2a.extensions.services.form import ( | ||
| FormServiceExtensionServer, | ||
| FormServiceExtensionSpec, | ||
| ) | ||
| from agentstack_sdk.server import Server | ||
|
|
||
| server = Server() | ||
|
|
||
|
|
||
| class FormData(BaseModel): | ||
| mood: str | None | ||
|
|
||
|
|
||
| @server.agent() | ||
| async def form_agent( | ||
| _message: Message, | ||
| form: Annotated[ | ||
| FormServiceExtensionServer, | ||
| FormServiceExtensionSpec.demand( | ||
| initial_form=FormRender( | ||
| title="How are you?", | ||
| fields=[TextField(id="mood", label="Mood", type="text", col_span=1)], | ||
| ) | ||
| ), | ||
| ], | ||
| ): | ||
| """Initial form agent""" | ||
| initial_form = form.parse_initial_form(model=FormData) | ||
| if initial_form is None: | ||
| yield "No form data received." | ||
| else: | ||
| yield f"Your mood is {initial_form.mood}" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| server.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Copyright 2025 © BeeAI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from typing import Annotated | ||
|
|
||
| from a2a.types import Message | ||
| from pydantic import BaseModel | ||
|
|
||
| from agentstack_sdk.a2a.extensions.common.form import ( | ||
| CheckboxField, | ||
| DateField, | ||
| FileField, | ||
| FileInfo, | ||
| FormRender, | ||
| MultiSelectField, | ||
| OptionItem, | ||
| SingleSelectField, | ||
| TextField, | ||
| ) | ||
| from agentstack_sdk.a2a.extensions.ui.form_request import FormRequestExtensionServer, FormRequestExtensionSpec | ||
| from agentstack_sdk.server import Server | ||
|
|
||
| server = Server() | ||
|
|
||
|
|
||
| class KitchenSink(BaseModel): | ||
| text_field: str | None | ||
| date_field: str | None | ||
| file_field: list[FileInfo] | None | ||
| singleselect_field: str | None | ||
| multiselect_field: list[str] | None | ||
| checkbox_field: bool | None | ||
|
|
||
|
|
||
| @server.agent() | ||
| async def form_request_agent( | ||
| _message: Message, | ||
| form_request: Annotated[ | ||
| FormRequestExtensionServer, | ||
| FormRequestExtensionSpec(), | ||
| ], | ||
| ): | ||
| """Request form agent""" | ||
| user_info = await form_request.request_form( | ||
| form=FormRender( | ||
| title="Kitchen Sink Form", | ||
| columns=2, | ||
| fields=[ | ||
| TextField(id="text_field", label="Text Field", col_span=1), | ||
| DateField(id="date_field", label="Date Field", col_span=1), | ||
| FileField(id="file_field", label="File Field", accept=["*/*"], col_span=2), | ||
| SingleSelectField( | ||
| id="singleselect_field", | ||
| label="Single-Select Field", | ||
| options=[ | ||
| OptionItem(id="option1", label="Option 1"), | ||
| OptionItem(id="option2", label="Option 2"), | ||
| ], | ||
| col_span=2, | ||
| ), | ||
| MultiSelectField( | ||
| id="multiselect_field", | ||
| label="Multi-Select Field", | ||
| options=[ | ||
| OptionItem(id="option1", label="Option 1"), | ||
| OptionItem(id="option2", label="Option 2"), | ||
| ], | ||
| col_span=2, | ||
| ), | ||
| CheckboxField( | ||
| id="checkbox_field", | ||
| label="Checkbox Field", | ||
| content="I agree to the terms and conditions.", | ||
| col_span=2, | ||
| ), | ||
| ], | ||
| ), | ||
| model=KitchenSink, | ||
| ) | ||
| if user_info is None: | ||
| yield "No user info received." | ||
| else: | ||
| yield user_info.model_dump_json() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| server.run() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably refactor this and use the extension client and parse as service extension cc @jezekra1