@samrahimi/smol-js 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  Agent: () => Agent,
34
34
  AgentLogger: () => AgentLogger,
35
35
  AgentMemory: () => AgentMemory,
36
+ AgentTool: () => AgentTool,
36
37
  CodeAgent: () => CodeAgent,
37
38
  FINAL_ANSWER_PROMPT: () => FINAL_ANSWER_PROMPT,
38
39
  FinalAnswerTool: () => FinalAnswerTool,
@@ -42,6 +43,7 @@ __export(index_exports, {
42
43
  OpenAIModel: () => OpenAIModel,
43
44
  Tool: () => Tool,
44
45
  UserInputTool: () => UserInputTool,
46
+ agentAsTool: () => agentAsTool,
45
47
  createTool: () => createTool,
46
48
  finalAnswerTool: () => finalAnswerTool,
47
49
  generateSystemPrompt: () => generateSystemPrompt,
@@ -226,7 +228,7 @@ var import_chalk = __toESM(require("chalk"));
226
228
  var fs = __toESM(require("fs"));
227
229
  var path = __toESM(require("path"));
228
230
  var os = __toESM(require("os"));
229
- var LOG_DIR = path.join(os.homedir(), ".smol-js");
231
+ var LOG_DIR = path.join(os.homedir(), ".smol-js/logs");
230
232
  var AgentLogger = class {
231
233
  level;
232
234
  logFile;
@@ -1340,7 +1342,7 @@ Thought: [Your reasoning about what to do]
1340
1342
 
1341
1343
  1. **Always use final_answer()**: When you have the complete answer, call \`final_answer(yourResult)\` to return it.
1342
1344
 
1343
- 2. **One action per step**: Execute one logical action per code block. Don't try to do everything at once.
1345
+ 2. **One action per step**: Execute one logical action per code block and one code block per inference step. You will be given additional steps to complete your work if it cannot be done safely in one step. Don't try to do everything at once because you need to make sure that your tools returned valid, useful data before going on to make use of that data. In particular, if you are a Manager agent who is invoking Sub-Agents as tools, do not script the entire workflow in one step, make sure that you get to review the work of your subagents at critical points before going on to the next step.
1344
1346
 
1345
1347
  3. **Handle errors gracefully**: If something fails, explain what went wrong and try a different approach.
1346
1348
 
@@ -1354,6 +1356,8 @@ Thought: [Your reasoning about what to do]
1354
1356
 
1355
1357
  8. **No require()**: Use \`await importPackage('name')\` for npm packages instead of require().
1356
1358
 
1359
+ 9. **Internet Access**: You can use fetch() to get data from the web as needed. However, if you have access to specialized tools for browsing / searching / retrieving information, use those first and fall back to fetch if they don't work
1360
+
1357
1361
  ## Examples
1358
1362
 
1359
1363
  ### Example 1: Simple calculation
@@ -1649,8 +1653,8 @@ var import_openai = __toESM(require("openai"));
1649
1653
  var DEFAULT_CONFIG = {
1650
1654
  modelId: "anthropic/claude-sonnet-4.5",
1651
1655
  baseUrl: "https://openrouter.ai/api/v1",
1652
- maxTokens: 4096,
1653
- temperature: 0.7,
1656
+ maxTokens: 65e3,
1657
+ temperature: 1,
1654
1658
  timeout: 12e4
1655
1659
  };
1656
1660
  var OpenAIModel = class extends Model {
@@ -1749,11 +1753,87 @@ var OpenAIModel = class extends Model {
1749
1753
  });
1750
1754
  }
1751
1755
  };
1756
+
1757
+ // src/tools/AgentTool.ts
1758
+ var AgentTool = class extends Tool {
1759
+ name;
1760
+ description;
1761
+ inputs = {
1762
+ task: {
1763
+ type: "string",
1764
+ description: "The task or question to delegate to this agent",
1765
+ required: true
1766
+ }
1767
+ };
1768
+ outputType = "string";
1769
+ agent;
1770
+ additionalContext;
1771
+ returnFullResult;
1772
+ constructor(config) {
1773
+ super();
1774
+ this.agent = config.agent;
1775
+ this.name = config.name ?? "managed_agent";
1776
+ this.additionalContext = config.additionalContext;
1777
+ this.returnFullResult = config.returnFullResult ?? false;
1778
+ this.description = config.description ?? this.generateDescription();
1779
+ }
1780
+ /**
1781
+ * Generate a default description based on the agent's configuration
1782
+ */
1783
+ generateDescription() {
1784
+ return `Delegates a task to a specialized agent.
1785
+ This agent can help with complex sub-tasks that require multiple steps.
1786
+ Pass a clear, specific task description and the agent will work autonomously to solve it.
1787
+ Returns the agent's final answer as a string.`;
1788
+ }
1789
+ /**
1790
+ * Execute the agent with the given task
1791
+ */
1792
+ async execute(args) {
1793
+ let task = args.task;
1794
+ if (this.additionalContext) {
1795
+ task = `${this.additionalContext}
1796
+
1797
+ Task: ${task}`;
1798
+ }
1799
+ const result = await this.agent.run(task, true);
1800
+ if (this.returnFullResult) {
1801
+ return {
1802
+ output: result.output,
1803
+ steps: result.steps.length,
1804
+ duration: result.duration
1805
+ };
1806
+ }
1807
+ const output = result.output;
1808
+ if (typeof output === "string") {
1809
+ return output;
1810
+ }
1811
+ return JSON.stringify(output, null, 2);
1812
+ }
1813
+ /**
1814
+ * Override toCodePrompt to provide a cleaner signature for nested agents
1815
+ */
1816
+ toCodePrompt() {
1817
+ return `
1818
+ /**
1819
+ * ${this.description}
1820
+ *
1821
+ * @param task - The task or question to delegate to this specialized agent
1822
+ * @returns The agent's answer as a string
1823
+ */
1824
+ async function ${this.name}(task: string): Promise<string> { ... }
1825
+ `.trim();
1826
+ }
1827
+ };
1828
+ function agentAsTool(agent, options) {
1829
+ return new AgentTool({ agent, ...options });
1830
+ }
1752
1831
  // Annotate the CommonJS export names for ESM import in node:
1753
1832
  0 && (module.exports = {
1754
1833
  Agent,
1755
1834
  AgentLogger,
1756
1835
  AgentMemory,
1836
+ AgentTool,
1757
1837
  CodeAgent,
1758
1838
  FINAL_ANSWER_PROMPT,
1759
1839
  FinalAnswerTool,
@@ -1763,6 +1843,7 @@ var OpenAIModel = class extends Model {
1763
1843
  OpenAIModel,
1764
1844
  Tool,
1765
1845
  UserInputTool,
1846
+ agentAsTool,
1766
1847
  createTool,
1767
1848
  finalAnswerTool,
1768
1849
  generateSystemPrompt,