Skip to content

refactor: Consolidate the logic of the agent and remove redundancy#93

Merged
edenreich merged 37 commits intomainfrom
refactor/general-improvements
Oct 10, 2025
Merged

refactor: Consolidate the logic of the agent and remove redundancy#93
edenreich merged 37 commits intomainfrom
refactor/general-improvements

Conversation

@edenreich
Copy link
Copy Markdown
Contributor

@edenreich edenreich commented Oct 8, 2025

Summary

Consolidate the logic of the agent and remove redundant code.

I'm deprecating the Run function in favor of using exclusively the RunWithStream to allow a more event-driven architecture.

The Run method is simple but it's not resilient when for example a connection drops or times-out - there is a lost of responses, better would be to stick to SSE in the backend, the A2A client that consumes the message can still decides whether they would like to receive SSE or Async Polling for task's updates.
The events are all cloud events for better standardisation and it's easier to add more events as pleased.

Also improve the examples, bump most examples to version 0.13.1 and use some examples with direct replace directive for using the latest features.

For those who used Run() in their custom tasks handler this method is going to be deleted so please always use pinned versions or modify the code to adopt the new event-driven architecture.

Fixed a non-critical issue, where context id and task id optional fields on the messages were not populated and were remained null.

TODOs

  • Regression tests - check that all examples still works as intended

    • ai-powered
    • ai-powered-streaming
    • artifacts-filesystem
    • artifacts-minio
    • artifacts-with-default-handlers
    • default-handlers
    • minimal
    • queue-storage
    • static-agent-card
    • streaming
    • tls-server
  • Cleanup the input required logic

  • Add a2a-debugger to all examples for better visibility

I think I should convert this to a more event-driven based architecture. It might be a breaking change but it would be clearer and easier to extend.

- Updated the version of the inference-gateway/adk module from v0.11.2 to v0.13.1 in multiple go.mod and go.sum files across examples and server directories.
- Refactored the AgentResponse struct to remove AdditionalMessages and directly append messages to task history.
- Modified the Run method in OpenAICompatibleAgentImpl to handle task history updates more efficiently.
- Streamlined input_required tool handling in agent_streamable.go and agent_toolbox.go, ensuring proper message flow and task state management.
- Updated tests to reflect changes in the agent response structure and behavior.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…reaming tasks

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
…ved clarity

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…handler

- Updated the AIStreamingTaskHandler to utilize RunWithStream for handling AI responses in a streaming manner.
- Accumulated response parts from streaming events and created a final response message.
- Enhanced task status management to reflect completion and history updates.

refactor: Improve Dockerfile build processes for client and server examples

- Modified Dockerfiles for ai-powered, default-handlers, artifacts-filesystem, and minimal examples to streamline build commands and paths.
- Ensured proper binary naming and reduced build context complexity.

chore: Update go.mod and go.sum files across examples

- Replaced the adk module version to v0.13.1 in multiple go.mod files for consistency.
- Cleaned up go.sum files by removing outdated entries.

fix: Adjust Docker Compose configurations for client and server services

- Updated Docker Compose files to correctly reference Dockerfile paths and build contexts for client and server services in various examples.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
@Joshswooft
Copy link
Copy Markdown
Contributor

Joshswooft commented Oct 9, 2025

Thank you for adding the much needed tests!!! I'll probably just have to re-do most of my stuff (https://github.com/Joshswooft/adk/tree/support-callbacks) once this is all merged as sorting out all the merge conflicts and new examples (again) is a lot of effort.

@edenreich
Copy link
Copy Markdown
Contributor Author

@Joshswooft I see, I had to refactor this, sorry for the conflicts with the files, I can help you resolve these if you push the changes.

I think now it is easier to add the callbacks functionality, when there are clear events in the system.

I've removed one of the method from the OpenAI-compatible agent (Run Method) which was redundant.

Also running some tests it feels more performant right now with SSE internally and we lose less data due to connectivity. Previously the Run was adding the messages to the storage at the end of all agent iterations.

Looking forward to see your changes 👍

…e build process and add agent arguments

Signed-off-by: Eden Reich <eden.reich@gmail.com>
… instead of remote version

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…le for a client and server

Reason - simply easier to maintain and creating more examples as the project grows ensuring consistency.

- Created new Dockerfile.client and Dockerfile.server in the examples directory to standardize the build process for client and server applications.
- Removed individual Dockerfiles from various example directories, consolidating them into the new standardized Dockerfiles.
- Updated docker-compose.yaml files across multiple examples to reference the new Dockerfile locations and include necessary build arguments (LD_FLAGS, EXAMPLE_PATH, COMPONENT).
- Ensured that build-time metadata is correctly passed to the Go build process for both client and server applications.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
… for client and server containers

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…th appropriate configurations

Signed-off-by: Eden Reich <eden.reich@gmail.com>
- Added markdownlint-cli2 package to the manifest for linting markdown files.
- Created a markdownlint configuration file to enforce line length and disable specific rules.
- Introduced a new task in Taskfile.yml to run markdownlint on example markdown files.
- Updated multiple example README files to improve formatting, add troubleshooting sections, and enhance clarity with a Table of Contents.
- Included troubleshooting instructions for using the A2A Debugger in various example READMEs.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
Built-in is a bad wording, because those tools are being registered (not a built-in tools that I'm planning for future versions) - built-in tools would be tools that are in the default toolbox.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
…er in docker-compose.yaml

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…adiness

Also expose the inference gateway locally in case the person wants to run the example locally without docker.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…ent waits for server readiness

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…e.yaml

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
… task listing

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
… docker-compose files

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…ng and add TaskID and ContextID to messages in task handler

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
…rver

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…rmissions

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
…using build-time variables instead

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…racking

Signed-off-by: Eden Reich <eden.reich@gmail.com>
@edenreich
Copy link
Copy Markdown
Contributor Author

edenreich commented Oct 9, 2025

I found out a huge flaw and inconsistency with the events, the task is streaming each delta to the client, which is not correct according to the protocol there is a TaskStatusUpdateEvent which should only emit when task status as changed - way less events.

Also I don't like the current event system it's not consistent enough some events are used with custom event names, I will transition all the events to be CloudEvents so they are more compatible and easier to consume. I'll probably also introduce another event to see deltas in case some clients are interested to also see the deltas (although according to the protocol those are internal to the agent, those deltas could be useful for client applications that want to show some visual effects of the internal work of the agents).

TODOs

  • Reconcile the events in the system - removing custom handler events and use cloudevents instead (openai-compatible agent -> a2a handler -> a2a protocol -> client).
  • Cleanup everywhere, where claude laziness make it use "any" type instead of proper types from the ADK.
  • Use more constants instead of hardcoded strings for event names for better maintainability.
  • Update streaming examples.

- Removed the extractDeltaText and extractTextFromParts functions from the client.
- Updated the client to directly handle TaskStatusUpdateEvent and extract text from TextPart.
- Modified the server's MockAgent to send initial task status events and stream responses as CloudEvents.
- Changed the StreamableTaskHandler interface to return CloudEvents instead of custom StreamEvent types.
- Updated task handler to process CloudEvents directly, simplifying event handling logic.
- Adjusted tests to reflect changes in message structure and event types.
- Added new event type for task status changes to improve clarity in event handling.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…on events

Signed-off-by: Eden Reich <eden.reich@gmail.com>
- Added go-envconfig dependency to multiple examples for improved configuration handling.
- Refactored main functions in various clients and servers to load configurations from environment variables.
- Enhanced logging to provide better context and information based on the environment.
- Updated health check and task submission logic to utilize the new configuration structure.
- Improved code readability and maintainability by consolidating configuration and logging setup.

Signed-off-by: Eden Reich <eden.reich@gmail.com>
…D, and TaskID

Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
Signed-off-by: Eden Reich <eden.reich@gmail.com>
…mproved clarity and type safety

Signed-off-by: Eden Reich <eden.reich@gmail.com>
@edenreich edenreich merged commit 54e5e71 into main Oct 10, 2025
1 check passed
@edenreich edenreich deleted the refactor/general-improvements branch October 10, 2025 16:45
ig-semantic-release-bot bot added a commit that referenced this pull request Oct 11, 2025
## [0.14.0](v0.13.1...v0.14.0) (2025-10-11)

### ✨ Features

* Add the callbacks ready to be used by the agent ([#94](#94)) ([84632f3](84632f3))
* **types:** Refactor Part deserialization to use concrete types ([#104](#104)) ([22d192e](22d192e)), closes [#102](#102)

### ♻️ Improvements

* Consolidate the logic of the agent and remove redundancy ([#93](#93)) ([54e5e71](54e5e71))
* **docker-compose:** Remove port mappings for server service to avoid confusion ([3df7b08](3df7b08))
* **server:** Remove handler duplication between A2AServerImpl and DefaultA2AProtocolHandler ([#101](#101)) ([75b9c20](75b9c20))

### 🐛 Bug Fixes

* Improve validation logic for task handler configuration ([#98](#98)) ([34d6354](34d6354))

### 👷 CI

* Add Prettier setup and formatting steps for Go and markdown files ([#105](#105)) ([f2a1994](f2a1994))

### 📚 Documentation

* **examples:** Add input-required flow examples ([#96](#96)) ([17764f3](17764f3))

### 🔧 Miscellaneous

* **deps:** Update claude-code to 2.0.8 and install gh cli version 2.81.0 in flox environment ([4d6e41a](4d6e41a))
@ig-semantic-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.14.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants