Hi! I want to clarify if my understanding is corre...
# koog-agentic-framework
a
Hi! I want to clarify if my understanding is correct: it seems that an agent can do only one run at a time, and the chat server should implement its own agent pool to serve multiple clients. If so, I would probably have more questions 😀
👍 1
d
As far as I understand it, there is no notion of session/user yet (or
memoryId
as LangChain calls it). So you'd have to handle that yourself if you need long-running conversations. Also, Agent contains all of its state, so indeed you'd need to have a pool of agents, and modify their state as needed before running them. @Vadim Briliantov please correct me, if I am wrong.
m
@ait Hello! Yeah, we assume that every agent is running only one session at a time
a
I assume something like code below should do the job, right?
Copy code
fun agentPool(maxAvailable: Int, factory: () -> AIAgent): AIAgentBase {
    return PooledAgent(Semaphore(maxAvailable), factory)
}

private class PooledAgent(
    private val semaphore: Semaphore,
    private val factory: () -> AIAgent
)
: AIAgentBase
{
    private val queue = ConcurrentLinkedQueue<AIAgent>()

    override suspend fun run(agentInput: String) {
        throw UnsupportedOperationException("PooledAgent does not support run()")
    }

    override suspend fun runAndGetResult(agentInput: String): String? =
        semaphore.withPermit {
            val agent = queue.poll() ?: factory()
            try {
                agent.runAndGetResult(agentInput)
            }
            finally {
                queue.offer(agent)
            }
        }
}
m
Kind of, yeah. As far as you’re not trying to run agent from different threads - it should be fine
a
Thanks.