From 5f284883b317d55d5feb7e4935d3a8840eaf1333 Mon Sep 17 00:00:00 2001 From: narawat Date: Fri, 21 Aug 2026 22:39:51 +0700 Subject: [PATCH] update --- README.md | 8 ++++---- README_tools.md | 6 +++--- src/YiemAgent.jl | 2 ++ src/api.jl | 10 +++++----- src/type.jl | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2f723ef..ba83600 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Julia framework for building agents with tool use and MCP (Model Context Protoco ```julia agent = YiemAgent.yiemAgent(llmCall; mcpServer=mcpServer, eventSink=yourSink) ``` -4. Call `runAgent(agent, message)` then `takeResponse(agent)` +4. Call `promptAgent(agent, message)` then `takeResponse(agent)` ## Architecture @@ -20,7 +20,7 @@ src/ ├── type.jl # Core types (messages, tools, agent state) ├── utils.jl # Message formatting, context preparation, validation ├── agentCore.jl # Agent loop, tool execution pipeline -├── api.jl # Public API (runAgent, takeResponse, followUp, stopAgent) +├── api.jl # Public API (promptAgent, takeResponse, followUp, stopAgent) └── toolRegistry.jl # Tool store, MCP discovery, listTools registration ``` @@ -114,7 +114,7 @@ Tools are discovered dynamically via MCP server: | Function | Description | |----------|-------------| -| `runAgent(agent, msg)` | Send a message to the agent's input channel | +| `promptAgent(agent, msg)` | Send a message to the agent's input channel | | `takeResponse(agent)` | Block and take the agent's response from output channel | | `followUp(agent, msg)` | Send a follow-up message while agent is still processing | | `stopAgent(agent)` | Gracefully stop the agent and close channels | @@ -122,7 +122,7 @@ Tools are discovered dynamically via MCP server: ## Agent Lifecycle 1. `yiemAgent()` spawns a background task (`_agentLoop`) listening on `inputChannel` and `followUpChannel` -2. User messages enter via `runAgent()` or `followUp()` +2. User messages enter via `promptAgent()` or `followUp()` 3. `_processMessage()` handles LLM calls, tool execution, and conversation history 4. Tool execution follows three phases: `prepareToolCall` → `executePreparedToolCall` → `finalizeExecutedToolCall` 5. `beforeToolCall`/`afterToolCall` hooks allow pre/post-processing of tool calls diff --git a/README_tools.md b/README_tools.md index c6ab65d..fb492f1 100644 --- a/README_tools.md +++ b/README_tools.md @@ -126,7 +126,7 @@ result = getWeather_tool.execute("call-1", Dict("city" => "Tokyo"), sig, op) **Via agent loop (production):** ``` -user message → runAgent(agent, Dict("role"=>"user", "content"=>...)) +user message → promptAgent(agent, Dict("role"=>"user", "content"=>...)) → _agentLoop detects message → @spawn _processMessage(agent) → prepareContext → formatMsgForLLM → llmCall → LLM returns tool_calls @@ -346,7 +346,7 @@ The `_agentLoop()` function runs as a background `@spawn` task, created when `yi ``` yiemAgent struct contains: - - inputChannel (Channel, capacity 16) ← user sends messages here via runAgent() + - inputChannel (Channel, capacity 16) ← user sends messages here via promptAgent() - followUpChannel (Channel, capacity 32) ← user sends follow-ups here via followUp() - outputChannel (Channel, capacity 16) ← agent sends responses here via takeResponse() ``` @@ -1243,7 +1243,7 @@ Each `toolStore` gets its own `listTool` instance bound to that store via `listT ``` USER SENDS MESSAGE - └─> runAgent(agent, "What's the weather in Tokyo?") + └─> promptAgent(agent, "What's the weather in Tokyo?") └─> put!(agent.inputChannel, Dict("role" => "user", "content" => [...])) diff --git a/src/YiemAgent.jl b/src/YiemAgent.jl index 372f80b..ccfee40 100644 --- a/src/YiemAgent.jl +++ b/src/YiemAgent.jl @@ -20,6 +20,8 @@ module YiemAgent include("api.jl") using .api + + export promptAgent, takeResponse, followUp, stopAgent diff --git a/src/api.jl b/src/api.jl index 04812e3..7bc924e 100644 --- a/src/api.jl +++ b/src/api.jl @@ -1,6 +1,6 @@ module api -export prompt +export promptAgent, takeResponse, followUp, stopAgent using JSON, DataStructures, Dates, UUIDs, HTTP, Random, PrettyPrinting, Serialization, DataFrames @@ -29,11 +29,11 @@ The agent processes messages from `inputChannel` in the background task. # Examples ```jldoctest -julia> runAgent(agent, Dict("role" => "user", "content" => "Hello!")) +julia> promptAgent(agent, Dict("role" => "user", "content" => "Hello!")) yiemAgent(...) ``` """ -function runAgent(agent::yiemAgent, msg::AbstractDict{String, Any}) +function promptAgent(agent::yiemAgent, msg::AbstractDict{String, Any}) put!(agent.inputChannel, msg) return agent end @@ -50,7 +50,7 @@ Blocks until the agent sends a response. - An `assistantMessage` instance representing the agent's response # Notes -- Use `runAgent(agent, msg)` to send a message before calling this function. +- Use `promptAgent(agent, msg)` to send a message before calling this function. # Examples ```jldoctest @@ -76,7 +76,7 @@ and before any tool call results are sent. - The same `agent` instance for chaining # Notes -- Use `runAgent(agent, msg)` for the primary message and `followUp(agent, msg)` for additional +- Use `promptAgent(agent, msg)` for the primary message and `followUp(agent, msg)` for additional messages while the agent is processing. - Follow-up messages are buffered in a separate channel (capacity 32 by default). diff --git a/src/type.jl b/src/type.jl index 013e809..ced7575 100644 --- a/src/type.jl +++ b/src/type.jl @@ -23,7 +23,7 @@ preparedToolCall, immediateOutcome, executedOutcome, finalizedOutcome, agentToolCallBatch, # Functions (defined elsewhere) - runAgent, takeResponse, followUp, stopAgent + promptAgent, takeResponse, followUp, stopAgent using Dates, UUIDs, DataStructures, JSON, NATS, Base.Threads