-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Agent & Tool Loop #2
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
Open
renatillas
wants to merge
7
commits into
Pevensie:main
Choose a base branch
from
renatillas:feat/agent-tool-loop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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 PR implements the agent/tool loop system for gai:
## New Modules
- \`gai/internal/coerce\` - Existential type pattern using identity function
(works on both Erlang and JavaScript targets)
- \`gai/tool\` - Extended with new ExecutableTool type that carries its own
executor. Type safety is preserved at definition time, then erased for
storage using the coerce pattern.
- \`gai/agent\` - Agent type that bundles provider, system prompt, and tools
with builder pattern API.
- \`gai/runtime\` - HTTP transport abstraction for target-agnostic requests.
- \`gai/agent/loop\` - Tool loop that orchestrates LLM calls with automatic
tool execution until completion or max iterations.
## Design Highlights
- Tools carry their own executor: no pattern matching on tool names needed
- Coerce pattern works on both Erlang and JS (uses identity function)
- Backwards compatible: legacy Tool(a) and UntypedTool APIs preserved
- Full test coverage for new functionality
## Example Usage
\`\`\`gleam
let weather_tool = tool.executable(
name: "get_weather",
description: "Get weather",
schema: weather_schema(),
execute: fn(ctx, args) { // args is fully typed!
Ok("Sunny in " <> args.location)
},
)
let my_agent = agent.new(provider)
|> agent.with_system_prompt("You are helpful")
|> agent.with_tool(weather_tool)
|> agent.with_max_iterations(5)
loop.run(my_agent, ctx, messages, runtime)
\`\`\`
See AGENT_DESIGN.md for full design documentation.
d1c5ae8 to
f3b78eb
Compare
- Replace UntypedTool with ToolSchema in request and providers - Update tool.gleam: remove legacy API, use tool() as constructor - Update all tests to use new API: - tool.tool() with execute parameter - tool.to_schema() instead of to_untyped() - Direct field access on ToolSchema - 194 tests passing
a880d25 to
692d9fe
Compare
Proves that tool args can be any type - the test uses Option(Unit) enum which would fail if args was incorrectly typed as String. Also restores internal/coerce.gleam for future use.
No need for a separate internal module - coerce is only used here.
943afcd to
e09820b
Compare
2a53879 to
2a65bab
Compare
2a65bab to
e9168f7
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
High-level API for agentic LLM workflows with automatic tool execution.
New Modules
gai/agentgai/agent/loopgai/runtimeTool Design
Tools carry their own executor with type-safe args:
Usage
Changes
tool.tool()- Creates tool with embedded executortool.ToolSchema- ReplacesUntypedToolfor request serializationagent.Agent- Minimal config (provider, tools, system_prompt, max_iterations)loop.run()/loop.run_with_config()- Executes agent with tool loopSee
AGENT_DESIGN.mdfor details.