fix: Improve agents profiles for Ollama

This commit is contained in:
Petr Mironychev
2026-06-28 23:37:28 +02:00
parent a6921f523a
commit 755263c4de
7 changed files with 61 additions and 9 deletions

View File

@@ -18,7 +18,10 @@ namespace QodeAssist {
SessionManager::SessionManager(AgentFactory *agentFactory, QObject *parent)
: QObject(parent)
, m_agentFactory(agentFactory)
{}
{
if (m_agentFactory)
connect(m_agentFactory, &AgentFactory::agentsChanged, this, &SessionManager::flushPool);
}
SessionManager::~SessionManager() = default;
@@ -101,7 +104,7 @@ Session *SessionManager::acquire(const QString &agentName, QString *errorOut)
auto &bucket = m_pool[agentName];
while (!bucket.isEmpty()) {
QPointer<Session> pooled = bucket.takeLast();
if (pooled && pooled->isValid()) {
if (pooled && pooled->isValid() && pooledAgentMatchesCurrent(pooled, agentName)) {
resetSession(pooled);
m_sessions.append(pooled);
return pooled.data();
@@ -154,6 +157,32 @@ void SessionManager::resetSession(Session *session)
}
}
bool SessionManager::pooledAgentMatchesCurrent(Session *session, const QString &agentName) const
{
if (!m_agentFactory)
return true;
Agent *agent = session ? session->agent() : nullptr;
if (!agent)
return false;
const AgentConfig *current = m_agentFactory->configByName(agentName);
if (!current)
return false;
const AgentConfig &snapshot = agent->config();
return snapshot.model == current->model
&& snapshot.providerInstance == current->providerInstance;
}
void SessionManager::flushPool()
{
for (auto &bucket : m_pool) {
for (const QPointer<Session> &pooled : bucket) {
if (pooled)
pooled->deleteLater();
}
}
m_pool.clear();
}
void SessionManager::removeSession(Session *session)
{
if (!session)