- 平台Platform
- Node.js
- 要求Requires
- Node 24 或更高;pnpm(版本由 packageManager 固定);一个支持 OpenAI Chat Completions 格式的接口的 API Key。目前还不能运行:入口 index.ts 尚未编写。Node 24 or later; pnpm (pinned through packageManager); an API key for any service speaking the OpenAI Chat Completions format. Not runnable yet: the index.ts entry point has not been written.
- 许可证License
- MIT
常见问题Questions
怎么不用 LangChain,用 TypeScript 自己写一个 AI agent?How do I build an AI agent in TypeScript without LangChain?
demo-agent 就是这样写的:模型层 llm.ts 直接用官方 openai SDK 调 Chat Completions,返回内容、工具调用和 token 用量;agent 循环(agent.ts)会是围绕这次调用的一个 while 循环,单独成一个文件。目前模型层已写好,循环还没开始。demo-agent is built that way: the model layer, llm.ts, calls Chat Completions through the official openai SDK and returns content, tool calls and token usage; the agent loop, agent.ts, will be a single-file while loop around that call. The model layer is written; the loop is not started yet.
现在能运行吗?Can I run it yet?
还不能。pnpm start 指向的 index.ts 还不存在,代码也还没对真实模型跑过。现在可以读 llm.ts 和 types.ts,看模型层是怎么写的。Not yet. pnpm start points at index.ts, which does not exist, and nothing has been run against a real model. For now, llm.ts and types.ts show how the model layer is written.
能用 DeepSeek、OpenRouter 或本地 Ollama 吗?Can I use DeepSeek, OpenRouter or a local Ollama model?
模型层用 OpenAI Chat Completions 协议,createLLM 接受 baseURL 参数,指向任何实现了这个协议的接口即可。目前还没有对任何真实接口验证过。The model layer speaks OpenAI Chat Completions and createLLM takes a baseURL, so any endpoint implementing that protocol can be used. It has not been checked against a live endpoint yet.
为什么调用推理模型时不能设 temperature?Why does a reasoning model reject my temperature setting?
推理模型会用 400 拒绝显式设置的非 1 temperature。所以 llm.ts 不给任何采样参数设默认值,只在调用方明确传入时才发送。Reasoning models reject an explicit temperature other than 1 with a 400. That is why llm.ts never defaults any sampling parameter and only sends one when the caller passes it.
工具调用之后为什么下一轮报 400?Why do I get a 400 on the turn after a tool call?
带 tool_calls 的 assistant 消息必须原样放回历史,而且其中每一个调用都要有自己对应的 tool 回复。少了任何一条,下一轮请求就会被拒。The assistant message carrying tool_calls must go back into history verbatim, and every call it made needs its own tool reply. Missing either one gets the next request rejected.
用什么许可证?What license is it under?
MIT。可以自由使用、修改和分发,包括商用,保留版权声明即可。MIT. You can use, change and distribute it, commercially or not, as long as the copyright notice is kept.
获取帮助Get help
发邮件到Email hi@max1874.com,或在 , or open an issue on GitHub 提 issue。写上版本和运行环境,能更快定位问题。. Include the version and your environment so the problem is easier to find.