DEV Community

오병진
오병진

Posted on • Originally published at velog.io

4 4 4 4 4

OpenAI Agents Are Language-Dependent

Recently, OpenAI released a generative AI project called openai-agents-python.

I believe the biggest difference in this release is the ability to register tools simply, as shown in the following code:

@function_tool
def get_weather(city: str) -> str:
    return f"the weather in {city} is sunny."

agent = agent(
    name="hello world",
    instructions="you are a helpful agent.",
    tools=[get_weather],
)
Enter fullscreen mode Exit fullscreen mode

Previously, developers had to manually write JSON schemas or use libraries to create them. This manual process meant that actual code and interfaces remained separate. The new release is notable because of the function_tool decorator, which automates JSON schema creation by extracting metadata from functions:

# 2. inspect function signature and get type hints
sig = inspect.signature(func)
type_hints = get_type_hints(func)
params = list(sig.parameters.items())
takes_context = False
filtered_params = []
Enter fullscreen mode Exit fullscreen mode

This functionality significantly reduces manual labor associated with writing JSON schemas.

However, this approach has a few limitations:

First, it only reads type annotations provided explicitly by users. Without these annotations, it cannot generate accurate JSON schemas.

Second, because it relies on reflection, it may not be supported in languages lacking proper reflection capabilities. In other words, it's "language-dependent."

Despite these limitations, the convenience is still impressive.

Is there something similar in TypeScript?

Interestingly, the Korean tech community identified this need early on and developed libraries in a similar direction—almost a year ahead. A Korean developer, Samchon, created typia and openapi.

These libraries allow TypeScript developers to automatically generate JSON schemas and validation code at compile-time, using only type definitions (interfaces) rather than full functions or classes.

You can see an example of an agent built using typia and openapi here.

Here's a snippet from that repository:

export const functions = typia.llm.application<tool, "chatgpt">().functions.map((func): ChatCompletionTool => {
  return {
    type: "function",
    function: {
      name: func.name,
      description: func.description,
      parameters: func.parameters as Record<string, any>,
    },
  };
});
Enter fullscreen mode Exit fullscreen mode

With this simple code, you can easily extract a list of tools as JSON schemas.

If you're curious about how this transformation works, you can check it out in the typia playground.

If you find these repositories helpful, consider giving them a star—it would encourage the maintainers greatly.

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay