@slashfi/agents-sdk 0.36.3 → 0.37.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/src/registry.ts CHANGED
@@ -24,6 +24,7 @@ import type {
24
24
  ToolContext,
25
25
  ToolDefinition,
26
26
  ToolSchema,
27
+ ToolSchemaSummary,
27
28
  Visibility,
28
29
  } from "./types.js";
29
30
  import { assertValidDefinition } from "./validate.js";
@@ -37,6 +38,21 @@ const DEFAULT_SUPPORTED_ACTIONS: AgentAction[] = [
37
38
  "read_resources",
38
39
  ];
39
40
 
41
+ /**
42
+ * Estimate the token count for a tool schema when serialized to JSON.
43
+ * Uses a rough heuristic: ~4 characters per token (conservative estimate
44
+ * that accounts for JSON structure, property names, and schema verbosity).
45
+ */
46
+ function estimateToolTokens(tool: ToolSchema): number {
47
+ const json = JSON.stringify({
48
+ name: tool.name,
49
+ description: tool.description,
50
+ inputSchema: tool.inputSchema,
51
+ ...(tool.outputSchema && { outputSchema: tool.outputSchema }),
52
+ });
53
+ return Math.ceil(json.length / 4);
54
+ }
55
+
40
56
  // ============================================
41
57
  // Agent Registry Interface
42
58
  // ============================================
@@ -601,7 +617,10 @@ export function createAgentRegistry(
601
617
  return registryObj;
602
618
 
603
619
  async function callInternal(request: CallAgentRequest): Promise<CallAgentResponse> {
604
- const agent = agents.get(request.path);
620
+ // Normalize path: try exact, then with @, then without @
621
+ const agent = agents.get(request.path)
622
+ ?? agents.get(`@${request.path}`)
623
+ ?? agents.get(request.path.replace(/^@/, ""));
605
624
 
606
625
  if (!agent) {
607
626
  return {
@@ -791,17 +810,45 @@ export function createAgentRegistry(
791
810
  ...(t.outputSchema && { outputSchema: t.outputSchema }),
792
811
  }));
793
812
 
813
+ // Full mode: return complete schemas (backward-compatible)
814
+ if (request.full) {
815
+ return {
816
+ success: true,
817
+ tools: toolSchemas,
818
+ description: agent.config?.description,
819
+ security: agent.config?.security,
820
+ resources: agent.config?.resources?.map((r) => ({
821
+ uri: r.uri,
822
+ name: r.name,
823
+ mimeType: r.mimeType,
824
+ content: r.content,
825
+ })),
826
+ } as CallAgentDescribeToolsResponse;
827
+ }
828
+
829
+ // Slim mode (default): summaries with token estimates
830
+ const toolSummaries: ToolSchemaSummary[] = toolSchemas.map((t) => ({
831
+ name: t.name,
832
+ description: t.description,
833
+ fullTokens: estimateToolTokens(t),
834
+ }));
835
+
836
+ const totalFullTokens = toolSummaries.reduce(
837
+ (sum, t) => sum + t.fullTokens,
838
+ 0,
839
+ );
840
+
794
841
  return {
795
842
  success: true,
796
- tools: toolSchemas,
843
+ toolSummaries,
797
844
  description: agent.config?.description,
798
845
  security: agent.config?.security,
799
846
  resources: agent.config?.resources?.map((r) => ({
800
847
  uri: r.uri,
801
848
  name: r.name,
802
849
  mimeType: r.mimeType,
803
- content: r.content,
804
850
  })),
851
+ context: `Use full: true to get complete tool schemas (~${(totalFullTokens / 1000).toFixed(1)}k tokens total)`,
805
852
  } as CallAgentDescribeToolsResponse;
806
853
  }
807
854
 
package/src/server.ts CHANGED
@@ -26,6 +26,7 @@
26
26
  */
27
27
 
28
28
  import type { AuthStore } from "./agent-definitions/auth.js";
29
+ import type { Visibility } from "./types.js";
29
30
  import {
30
31
  type SecretStore,
31
32
  processSecretParams,
@@ -487,7 +488,7 @@ function getToolDefinitions(schemas?: AgentServerOptions["schemas"]) {
487
488
  {
488
489
  name: "call_agent",
489
490
  description:
490
- "Execute a tool on a registered agent. Provide the agent path and tool name.\n\nSupported actions:\n- invoke: Fire-and-forget agent invocation\n- ask: Invoke and wait for response\n- execute_tool: Call a specific tool on an agent\n- describe_tools: Get tool schemas for an agent\n- load: Get agent definition/system prompt\n- list_resources: List all resources available on an agent (docs, auth instructions, config schemas, etc.)\n- read_resources: Fetch one or more resources by URI",
491
+ "Execute a tool on a registered agent. Provide the agent path and tool name.\n\nSupported actions:\n- invoke: Fire-and-forget agent invocation\n- ask: Invoke and wait for response\n- execute_tool: Call a specific tool on an agent\n- describe_tools: Get tool schemas for an agent (slim by default; use full: true for complete schemas)\n- load: Get agent definition/system prompt\n- list_resources: List all resources available on an agent (docs, auth instructions, config schemas, etc.)\n- read_resources: Fetch one or more resources by URI",
491
492
  inputSchema: schemas?.callAgent
492
493
  ? zodToOpenAiJsonSchema(schemas.callAgent)
493
494
  : callAgentInputSchema,
@@ -697,7 +698,7 @@ export function createAgentServer(
697
698
  agent.config?.name ?? "",
698
699
  agent.config?.description ?? "",
699
700
  ...agent.tools
700
- .filter((t) => canSeeTool(t, auth))
701
+ .filter((t) => canSeeTool(t, auth, (agent.visibility ?? agent.config?.visibility ?? 'internal') as Visibility))
701
702
  .map((t) => `${t.name} ${t.description}`),
702
703
  ].join(" "),
703
704
  }));
@@ -764,7 +765,7 @@ export function createAgentServer(
764
765
  mimeType: r.mimeType,
765
766
  })),
766
767
  tools: agent.tools
767
- .filter((t) => canSeeTool(t, auth))
768
+ .filter((t) => canSeeTool(t, auth, (agent.visibility ?? agent.config?.visibility ?? 'internal') as Visibility))
768
769
  .map((t) => t.name),
769
770
  })),
770
771
  };
package/src/types.ts CHANGED
@@ -646,6 +646,17 @@ export interface ToolSchema {
646
646
  outputSchema?: JsonSchema;
647
647
  }
648
648
 
649
+ /**
650
+ * Slim tool summary for describe_tools when full=false (default).
651
+ * Omits verbose inputSchema/outputSchema to save context tokens.
652
+ */
653
+ export interface ToolSchemaSummary {
654
+ name: string;
655
+ description: string;
656
+ /** Estimated token count if full schema were returned for this tool */
657
+ fullTokens: number;
658
+ }
659
+
649
660
  // ============================================
650
661
  // Agent Definition
651
662
  // ============================================
@@ -749,13 +760,18 @@ export interface CallAgentExecuteToolResponse {
749
760
  /** Success response for describe_tools */
750
761
  export interface CallAgentDescribeToolsResponse {
751
762
  success: true;
752
- tools: ToolSchema[];
763
+ /** Full tool schemas (when full=true) */
764
+ tools?: ToolSchema[];
765
+ /** Slim tool summaries (when full=false/omitted) */
766
+ toolSummaries?: ToolSchemaSummary[];
753
767
  /** Agent description */
754
768
  description?: string;
755
769
  /** Security scheme (if any) */
756
770
  security?: SecuritySchemeSummary;
757
771
  /** Available resources (e.g., AUTH.md) */
758
772
  resources?: Array<{ uri: string; name?: string; mimeType?: string }>;
773
+ /** Human-readable hint about full mode */
774
+ context?: string;
759
775
  }
760
776
 
761
777
  /** A resolved agent ref with its discovered tools */