feat: implement agent global state#400
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| setIsAgentStopped: () => void; | ||
| setAgent: (newAgent: AutonomousAgent | null) => void; |
There was a problem hiding this comment.
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
|
|
||
| const handleStopAgent = () => { | ||
| agent?.stopAgent(); | ||
| setIsAgentStopped(); |
There was a problem hiding this comment.
@asim-shrestha removed setIsAgentStopped() since there is already a useEffect hook that update IsAgentStopped whenever agent is removed
Lines 72 to 74 in 6c58802
awtkns
left a comment
There was a problem hiding this comment.
looking good! I will wait for @asim-shrestha though
| 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.
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.
made it more concise 🎉
AgentGPT/src/types/agentTypes.ts
Lines 70 to 77 in a832040
keepingAGENT_STATUS_RUNNING and AGENT_STATUS_STOPPED because the strings "running" and "stopped" are referenced in many places.
| enabledClassName={"bg-red-600 hover:bg-red-400"} | ||
| > | ||
| {shouldAgentStop ? ( | ||
| {!isAgentStopped && agent === null ? ( |
There was a problem hiding this comment.
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.
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
CC: @asim-shrestha
There was a problem hiding this comment.
Yeah lets refactor this after
No description provided.