Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AgentNetwork (Experimental) #2744

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

AgentNetwork (Experimental) #2744

wants to merge 23 commits into from

Conversation

abhiaiyer91
Copy link
Contributor

@abhiaiyer91 abhiaiyer91 commented Mar 4, 2025

Vibe coded this! It works mediocrely. Will have to make it better

Copy link

codesandbox bot commented Mar 4, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Mar 4, 2025

⚠️ No Changeset found

Latest commit: f2cb941

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
assistant-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 11:51am
bird-checker ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 11:51am
crypto-chatbot ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 11:51am
mastra ❌ Failed (Inspect) Mar 12, 2025 11:51am
mastra-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 11:51am
openapi-spec-writer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 11:51am
travel-ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 11:51am

Copy link

promptless bot commented Mar 4, 2025

📝 Documentation updates detected! You can review documentation updates here

Comment on lines +16 to +37
// const { memory } = useMemory(networkId!);
// const navigate = useNavigate();
const { messages, isLoading: isMessagesLoading } = useMessages({
agentId: networkId!,
threadId: threadId!,
memory: false,
});

// const [sidebar, setSidebar] = useState(true);
// const {
// threads,
// isLoading: isThreadsLoading,
// mutate: refreshThreads,
// } = useThreads({ resourceid: networkId!, agentId: networkId!, isMemoryEnabled: !!memory?.result });

// useEffect(() => {
// if (memory?.result && !threadId) {
// // use @lukeed/uuid because we don't need a cryptographically secure uuid (this is a debugging local uuid)
// // using crypto.randomUUID() on a domain without https (ex a local domain like local.lan:4111) will cause a TypeError
// navigate(`/networks/${networkId}/chat/${uuid()}`);
// }
// }, [memory?.result, threadId]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this commented code? Should it be uncommented or deleted?

Comment on lines +51 to +74
{/* {sidebar && memory?.result ? (
<div className="border-r">
<div className="p-4">
<h3 className="text-sm font-medium text-mastra-el-5 mb-2">Network Conversations</h3>
{isThreadsLoading ? (
<p className="text-sm text-mastra-el-4">Loading threads...</p>
) : threads.length === 0 ? (
<p className="text-sm text-mastra-el-4">No conversations yet</p>
) : (
<div className="space-y-2">
{threads.map((thread) => (
<div
key={thread.id}
className={`p-2 rounded-md cursor-pointer text-sm ${thread.id === threadId ? 'bg-mastra-bg-3 text-mastra-el-5' : 'hover:bg-mastra-bg-2 text-mastra-el-4'}`}
onClick={() => navigate(`/networks/${networkId}/chat/${thread.id}`)}
>
{thread.name || 'Conversation'}
</div>
))}
</div>
)}
</div>
</div>
) : null} */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

type AgentTool = ReturnType<typeof createTool>;

// Create tools from agents with state tracking
const agentAsTools = this.agents.reduce<Record<string, AgentTool>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought for a later day: during the demo earlier the multi-step agent calling was a little slow and it just occured to me we could give the router agent a parallel agent tool so it could message multiple agents, they could generate at the same time, and it could get the result back. ex input args where each key is the name of an agent and the value is the message to send.

{ agentA: "do x", agentB: "do y" }

Res would match:

{ agentA: "As a large language model...", agentB: "lol" }

Copy link
Contributor

@TylerBarnes TylerBarnes Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice thing is this could be a single tool then. The router could choose to call one or more agents with it


const result = await agent.generate(agentContext, {
context: this.current_state?.lastResult
? [{ role: 'assistant', content: this.current_state?.lastResult }]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not important for this PR but we could use memory for this

Comment on lines +160 to +180
getNetworkState: createTool({
id: 'getNetworkState',
description: 'Get the current state of the agent network, including previous agent results and call history',
inputSchema: z.object({}),
outputSchema: z.object({
state: z.object({
callCount: z.number(),
lastResult: z.any(),
input: z.string(),
agentResults: z.record(z.string()),
agentHistory: z.array(
z.object({
agent: z.string(),
input: z.string(),
result: z.string(),
timestamp: z.string(),
}),
),
stateData: z.record(z.unknown()),
}),
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could use a huge amount of tokens - isn't this covered by the agent tool responses in each agent tool call? Since the tool call args and results will be in context for the router agent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants