Skip to content

Commit 4ff08bd

Browse files
committed
fix
1 parent e23bb68 commit 4ff08bd

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/content/changelog/agents/2025-03-17-npm-i-agents.mdx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ sed -i 's/agents-sdk/agents/g' $(grep -rl 'agents-sdk' .)
3737

3838
Future updates will be pushed to the new `agents` package, and the older package will be marked as deprecated.
3939

40-
#### Multi-Agent applications and RPC <Badge text="New" variant="tip" size="small" />
40+
#### Agents SDK updates <Badge text="New" variant="tip" size="small" />
4141

4242
We've added a number of big new features to the Agents SDK over the past few weeks, including:
4343

@@ -49,17 +49,6 @@ We've added a number of big new features to the Agents SDK over the past few wee
4949

5050
We've also fixed a number of bugs with state synchronization and the React hooks.
5151

52-
<TypeScriptExample>
53-
54-
```ts
55-
import { Agent } from 'agents';
56-
57-
// TODO: example of Multi-Agent or similar here
58-
class MyAgent extends Agent {}
59-
60-
```
61-
</TypeScriptExample>
62-
6352
#### Call Agent methods from your client code <Badge text="New" variant="tip" size="small" />
6453

6554
We've added a new [`@callable()`](/agents/api-reference/agents-api/) decorator for defining methods that can be called directly from clients. This allows you call methods from within your client code: you can call methods (with arguments) and get native JavaScript objects back.
@@ -73,7 +62,7 @@ import { Agent, callable } from 'agents';
7362
// TODO: replace this with a real example
7463
class MyAgent extends Agent {
7564
@callable()
76-
async getHistory(limit: number): Promise<string[]> {
65+
async getHistory(limit = 5: number): Promise<string[]> {
7766
// Allow a client to directly fetch chat history
7867
return this.state.chatHistory.slice(-limit)
7968
}
@@ -85,7 +74,7 @@ const { call } = useAgent({ agent: "rpc" });
8574
const fetchUserHistory = async () => {
8675
try {
8776
setLoading(true);
88-
const result = await call("getHistory(5)");
77+
const result = await call("getHistory");
8978
addToast(`Regular RPC result: ${result}`, "success");
9079
} catch (error) {
9180
addToast(`Error: ${error}`, "error");

src/content/docs/agents/api-reference/agents-api.mdx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,24 +532,24 @@ export class YourAgent extends Agent {
532532
)
533533
`;
534534
}
535-
535+
536536
async createUser(id: string, name: string, email: string) {
537537
// Insert a new user
538538
this.sql`
539539
INSERT INTO users (id, name, email, created_at)
540540
VALUES (${id}, ${name}, ${email}, ${Date.now()})
541541
`;
542542
}
543-
543+
544544
async getUserById(id: string): Promise<User | null> {
545545
// Query a user by ID
546546
const users = this.sql<User>`
547547
SELECT * FROM users WHERE id = ${id}
548548
`;
549-
549+
550550
return users.length ? users[0] : null;
551551
}
552-
552+
553553
async searchUsers(term: string): Promise<User[]> {
554554
// Search users with a wildcard
555555
return this.sql<User>`
@@ -742,7 +742,7 @@ function useAgent<State = unknown>(
742742
```tsx
743743
// Example of using useAgent in a React component
744744
import { useAgent } from "agents/react";
745-
import { useState, useEffect } from "react";
745+
import { useState } from "react";
746746

747747
interface TaskState {
748748
tasks: Array<{ id: string; text: string; completed: boolean }>;
@@ -765,15 +765,15 @@ function TaskManager() {
765765
onClose: () => console.log("Disconnected from task manager agent")
766766
});
767767

768-
function addTask(e) {
768+
function addTask(e: React.FormEvent) {
769769
e.preventDefault();
770770
if (!newTask.trim()) return;
771771

772772
// Update the Agent's state
773773
agent.setState({
774774
...agent.state,
775775
tasks: [
776-
...agent.state?.tasks || [],
776+
...(agent.state?.tasks || []),
777777
{ id: Date.now().toString(), text: newTask, completed: false }
778778
]
779779
});
@@ -784,7 +784,6 @@ function TaskManager() {
784784
return (
785785
<div>
786786
<h1>Task Manager</h1>
787-
788787
<form onSubmit={addTask}>
789788
<input
790789
value={newTask}
@@ -793,17 +792,16 @@ function TaskManager() {
793792
/>
794793
<button type="submit">Add</button>
795794
</form>
796-
797795
<ul>
798796
{agent.state?.tasks?.map(task => (
799-
<li key={task.id}>
800-
{task.text}
801-
</li>
797+
<li key={task.id}>{task.text}</li>
802798
))}
803799
</ul>
804800
</div>
805801
);
806802
}
803+
804+
export default TaskManager;
807805
```
808806

809807
</TypeScriptExample>

0 commit comments

Comments
 (0)