feat(agent): implement multi-step agent loop with tool-calling support - #1
Merged
Conversation
- WeatherTool: mock weather query by city name - CalculatorTool: evaluate math expressions via Function constructor - barrel index re-exports both tools
agentLoop() streams model output step by step, handles text-delta / tool-call / tool-result events from fullStream, and exits when no further tool calls are made; hard-capped at MAX_STEPS = 10
- Replace inline streamText call with agentLoop() - Register WeatherTool and CalculatorTool in the tools map - Update system prompt to reflect tool-use capability - Bump startup banner to v0.2.0 - Agent Loop
Add src/version.ts to re-export the version string from package.json, replacing the hardcoded literal in the startup banner of index.ts
Importing package.json via @types/node triggers type declaration errors; skipLibCheck suppresses them without affecting project type safety
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
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.
Overview
Upgrades the single-turn
streamTextcall to a multi-step agent loop that lets the model call tools, inspect results, and continue reasoning — all within a single user turn.Changes
New:
src/tools/WeatherToolCalculatorToolBoth tools are re-exported via a barrel
index.ts.New:
src/agent-loop.tsImplements
agentLoop(model, tools, messages, system):fullStreamevents:text-delta,tool-call,tool-resultMAX_STEPS = 10to prevent runaway loopsModified:
src/index.tsstreamTextcall withagentLoop()WeatherToolandCalculatorToolin the tools mapOther
src/version.ts: reads the version string frompackage.json, removing the hardcoded literal from the startup bannertsconfig.json: enablesskipLibCheckto suppress type declaration errors introduced by the JSON module importTesting
Follow-up
WeatherToolto a real weather APIagentLoopstep logic and toolexecutefunctionsMAX_STEPSconfigurable