AI-Engineer-Foundation / agent-protocol

Common interface for interacting with AI agents. The protocol is tech stack agnostic - you can use it with any framework for building agents.

Home Page:https://agentprotocol.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create TS Agent SDK

ValentaTomas opened this issue · comments

Create Agent SDK in TypeScript that works the same way as Python SDK (https://github.com/e2b-dev/sdk/tree/main/agent/python) - users have to just implement one hook and the agent will be wrapped in a webserver that complies with the Agent Communication Protocol.

There is already some initial code for this SDK present in the https://github.com/e2b-dev/sdk/tree/main/agent/js. It is using express-openapi-validator to generate boilerplate handlers from the OpenAPI spec.

@ValentaTomas Do you want the functions to remain in python's standard_function_naming_format, or should I also change them to camelCase?

e.g. listAgentTaskSteps?

It should be camelCase - approach it like a normal TS project 👍

Reference #4

Is this looking good so far? I wrote everything up to where I think it will sit, but was having issues testing it with the openapi validator stuff, which is what I'll be focusing on now.

Duplicating some comments I made in the discord thread for longevity's sake, along with some extra things.
Still referencing PR #4.

On tsup

I replaced tsup with a package called microbundle (https://github.com/developit/microbundle) and published it to the npm registry under jzanecook-e2b-sdk-test (https://www.npmjs.com/package/jzanecook-e2b-sdk-test) and it worked. I was able to run the minimal agent using this setup. With the upcoming commit, I'll be making the PR merge request.

On function and variable naming

I ran into issues with openapi when I renamed task_id to taskId which makes sense, so all of the API routes should work properly compared to the spec. I will write unit tests for this as well so that there's a bonafide way to check that, since I really only made a task and parsed through the tasks (like 1/3rd of the API).

On package naming

agent-sdk is currently taken by a random person, who has pushed a package with nothing but a readme. AKA it's "parked" so unless you have magic powers I would recommend perhaps @e2b/agent-sdk which is what I named it to.

On the README formatting

If you look at the test package I created on NPM you will notice that it's got two logos, but on GitHub it won't. I'm sure NPM will add that feature at some point, but who knows when.

On the topic of the models/types

I initially used a package called pydantic2ts and then tweaked further. It seems like all of the types are working as they should in the python sdk, but since I haven't rigorously tested it, there's always the possibility that they aren't up to snuff.

On the Agent class itself

In the Python code you call the Agent class (with no constructor) then a static function that registers the task_handler, then the static function that starts the webserver.

As an alternative to that, I just made it into a constructor here which somewhat simplifies it.

On the examples

I'm actually not familiar with any typescript-based AI agents (sorry unicorn, I didn't wanna deep dive the list) so I only implemented the minimal example for now.

And finally

I think this is a good starting point, and due to it's overall simplicity I think it can also be converted into a plethora of other languages. I've been planning my agent out in Rust, so I might make an SDK for that (provided that this one serves its intended purpose).

Looking forward to your feedback!

I believe we can mark this as closed. 👍

Let's just finish the README.md so is similar to the one for Python SDK, package.json so it has all the necessary info and then I think @jakubno can release it 👍

I think this may have accidentally came out like @jzanecook shouldn't do any of these tasks. I think @jzanecook can finish both the README.md and package.json if he has time and feels like it. Right @jakubno @ValentaTomas?

Yeah, example of the package could be (https://github.com/devbookhq/sdk/blob/master/package.json) and the analogous README is in the Python SDK.

Gotcha, so for the package you want the repo info, license, keywords, and other metadata (the scripts/files are fine as are right?) And in the README just to fill it out to make it match the python one with the examples (and no E2B logo like I had it before)?

Oh, and rather than the apache license It's the MIT license, right?

Please reference #10, a PR has been made.

@jakubno I guess we can close this? Or Em I missing something?

Yes, it's done and published. Closing the issue.

Thanks @jzanecook for implementation. We appreciate your contribution 🫡