-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
feat: implement agent global state #400
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/components/stores/agentStore.ts
Outdated
setIsAgentStopped: () => void; | ||
setAgent: (newAgent: AutonomousAgent | null) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an interface of
removeAgent: () => void;
setAgent: (newAgent: AutonomousAgent) => void;
Might make more sense. Remove agent would agent.stop(), setAgent(null) and also update isAgentStopped
…implement_agent_global_state
src/pages/index.tsx
Outdated
@@ -115,7 +114,6 @@ const Home: NextPage = () => { | |||
|
|||
const handleStopAgent = () => { | |||
agent?.stopAgent(); | |||
setIsAgentStopped(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asim-shrestha removed setIsAgentStopped()
since there is already a useEffect hook that update IsAgentStopped
whenever agent is removed
Lines 72 to 74 in 6c58802
useEffect(() => { | |
setIsAgentStopped(); | |
}, [agent, setIsAgentStopped]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good! I will wait for @asim-shrestha though
src/types/agentTypes.ts
Outdated
export const [AGENT_STATUS_RUNNING, AGENT_STATUS_STOPPED] = [ | ||
"running" as const, | ||
"stopped" as const, | ||
]; | ||
|
||
const AgentStatusSchema = z.union([ | ||
z.literal(AGENT_STATUS_RUNNING), | ||
z.literal(AGENT_STATUS_STOPPED), | ||
z.literal(""), | ||
]); | ||
|
||
export type AgentStatus = z.infer<typeof AgentStatusSchema>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a hard to work with. Any reason we cant do the below?
export const [AGENT_STATUS_RUNNING, AGENT_STATUS_STOPPED] = [ | |
"running" as const, | |
"stopped" as const, | |
]; | |
const AgentStatusSchema = z.union([ | |
z.literal(AGENT_STATUS_RUNNING), | |
z.literal(AGENT_STATUS_STOPPED), | |
z.literal(""), | |
]); | |
export type AgentStatus = z.infer<typeof AgentStatusSchema>; | |
export type AgentStatus = "running" | "stopped" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made it more concise 🎉
AgentGPT/src/types/agentTypes.ts
Lines 70 to 77 in a832040
export const [AGENT_STATUS_RUNNING, AGENT_STATUS_STOPPED] = [ | |
"running" as const, | |
"stopped" as const, | |
]; | |
export type AgentStatus = | |
| typeof AGENT_STATUS_RUNNING | |
| typeof AGENT_STATUS_STOPPED; |
keepingAGENT_STATUS_RUNNING
and AGENT_STATUS_STOPPED
because the strings "running" and "stopped" are referenced in many places.
onClick={handleStopAgent} | ||
enabledClassName={"bg-red-600 hover:bg-red-400"} | ||
> | ||
{shouldAgentStop ? ( | ||
{!isAgentStopped && agent === null ? ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this makes semantic sense. The above is saying:
"If the agent is not stopped and the agent exists then show stopping"
^ not sure that is right semantically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, I could be wrong but this might be outdated code and imo we should just remove this completely.
my understanding is that this is handling a state where agent has been shutdown (i.e. set to null
) but the agent?.isRunning
has not been set to false
In today's code, agent?.isRunning
and setAgent(null)
happen simultaneous. I don't think this state would happen
AgentGPT/src/components/AutonomousAgent.ts
Lines 255 to 260 in 4e83cd0
stopAgent() { | |
this.sendManualShutdownMessage(); | |
this.isRunning = false; | |
this.shutdown(); | |
return; | |
} |
CC: @asim-shrestha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah lets refactor this after
No description provided.