@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.mjs CHANGED
@@ -175,7 +175,7 @@ import chalk from "chalk";
175
175
  import * as fs from "fs";
176
176
  import * as path from "path";
177
177
  import * as os from "os";
178
- var LOG_DIR = path.join(os.homedir(), ".smol-js");
178
+ var LOG_DIR = path.join(os.homedir(), ".smol-js/logs");
179
179
  var AgentLogger = class {
180
180
  level;
181
181
  logFile;
@@ -1289,7 +1289,7 @@ Thought: [Your reasoning about what to do]
1289
1289
 
1290
1290
  1. **Always use final_answer()**: When you have the complete answer, call \`final_answer(yourResult)\` to return it.
1291
1291
 
1292
- 2. **One action per step**: Execute one logical action per code block. Don't try to do everything at once.
1292
+ 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.
1293
1293
 
1294
1294
  3. **Handle errors gracefully**: If something fails, explain what went wrong and try a different approach.
1295
1295
 
@@ -1303,6 +1303,8 @@ Thought: [Your reasoning about what to do]
1303
1303
 
1304
1304
  8. **No require()**: Use \`await importPackage('name')\` for npm packages instead of require().
1305
1305
 
1306
+ 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
1307
+
1306
1308
  ## Examples
1307
1309
 
1308
1310
  ### Example 1: Simple calculation
@@ -1598,8 +1600,8 @@ import OpenAI from "openai";
1598
1600
  var DEFAULT_CONFIG = {
1599
1601
  modelId: "anthropic/claude-sonnet-4.5",
1600
1602
  baseUrl: "https://openrouter.ai/api/v1",
1601
- maxTokens: 4096,
1602
- temperature: 0.7,
1603
+ maxTokens: 65e3,
1604
+ temperature: 1,
1603
1605
  timeout: 12e4
1604
1606
  };
1605
1607
  var OpenAIModel = class extends Model {
@@ -1698,10 +1700,86 @@ var OpenAIModel = class extends Model {
1698
1700
  });
1699
1701
  }
1700
1702
  };
1703
+
1704
+ // src/tools/AgentTool.ts
1705
+ var AgentTool = class extends Tool {
1706
+ name;
1707
+ description;
1708
+ inputs = {
1709
+ task: {
1710
+ type: "string",
1711
+ description: "The task or question to delegate to this agent",
1712
+ required: true
1713
+ }
1714
+ };
1715
+ outputType = "string";
1716
+ agent;
1717
+ additionalContext;
1718
+ returnFullResult;
1719
+ constructor(config) {
1720
+ super();
1721
+ this.agent = config.agent;
1722
+ this.name = config.name ?? "managed_agent";
1723
+ this.additionalContext = config.additionalContext;
1724
+ this.returnFullResult = config.returnFullResult ?? false;
1725
+ this.description = config.description ?? this.generateDescription();
1726
+ }
1727
+ /**
1728
+ * Generate a default description based on the agent's configuration
1729
+ */
1730
+ generateDescription() {
1731
+ return `Delegates a task to a specialized agent.
1732
+ This agent can help with complex sub-tasks that require multiple steps.
1733
+ Pass a clear, specific task description and the agent will work autonomously to solve it.
1734
+ Returns the agent's final answer as a string.`;
1735
+ }
1736
+ /**
1737
+ * Execute the agent with the given task
1738
+ */
1739
+ async execute(args) {
1740
+ let task = args.task;
1741
+ if (this.additionalContext) {
1742
+ task = `${this.additionalContext}
1743
+
1744
+ Task: ${task}`;
1745
+ }
1746
+ const result = await this.agent.run(task, true);
1747
+ if (this.returnFullResult) {
1748
+ return {
1749
+ output: result.output,
1750
+ steps: result.steps.length,
1751
+ duration: result.duration
1752
+ };
1753
+ }
1754
+ const output = result.output;
1755
+ if (typeof output === "string") {
1756
+ return output;
1757
+ }
1758
+ return JSON.stringify(output, null, 2);
1759
+ }
1760
+ /**
1761
+ * Override toCodePrompt to provide a cleaner signature for nested agents
1762
+ */
1763
+ toCodePrompt() {
1764
+ return `
1765
+ /**
1766
+ * ${this.description}
1767
+ *
1768
+ * @param task - The task or question to delegate to this specialized agent
1769
+ * @returns The agent's answer as a string
1770
+ */
1771
+ async function ${this.name}(task: string): Promise<string> { ... }
1772
+ `.trim();
1773
+ }
1774
+ };
1775
+ function agentAsTool(agent, options) {
1776
+ return new AgentTool({ agent, ...options });
1777
+ }
1701
1778
  export {
1702
1779
  Agent,
1703
1780
  AgentLogger,
1704
1781
  AgentMemory,
1782
+ AgentTool,
1705
1783
  CodeAgent,
1706
1784
  FINAL_ANSWER_PROMPT,
1707
1785
  FinalAnswerTool,
@@ -1711,6 +1789,7 @@ export {
1711
1789
  OpenAIModel,
1712
1790
  Tool,
1713
1791
  UserInputTool,
1792
+ agentAsTool,
1714
1793
  createTool,
1715
1794
  finalAnswerTool,
1716
1795
  generateSystemPrompt,